CS2030 AY19/20 Semester 2
  • Introduction
  • Textbook Contributions
  • Peer Learning Tasks
  • Piazza Participation
  • Setting Up Lab Environment
  • Setting Up Java
  • Setting Up Vim
  • Setting Up MacVim
  • Setting Up Sunfire and PE Nodes
  • Setting Up Checkstyle
  • Textbook
  • CS2030 Java Style Guide
  • CS2030 Javadoc Specification
  • JDK 11 Download Link
  • Codecrunch
  • Github Repo
  • Piazza Forum

  • Unbounded Wildcards


    Edit the material here!

    This was adapted from Question 462 from Piazza.

    <?> is known as the unbounded wildcard. This is used to infer to unknown types. So, List<?> inherently means a List of unknown types This be the mantra of the day.

    Let us break it down. List<?> means a List of unknown types. If it is a List of unknown types, you should be able to insert a string into this list. However, this means you are inserting an object with a known type, which breaks the mantra. List<?> has almost the same meaning as List<? extends Object>, which means you are only able to take out objects of which you do not know the data type.

    As a result, you only can add null values into List<?>, since null is actually an unknown data type. As a result, we should not use List<?> to insert data into it. We should only use it when we want to refer to something of unknown data type inside the List<?>

    You can read more about <?> in the Java documentation!