Wildcard (Java)

In the Java programming language, the wildcard ? is a special kind of type argument[1] that controls the type safety of the use of generic (parameterized) types.[2] It can be used in variable declarations and instantiations as well as in method definitions, but not in the definition of a generic type.[3][4] This is a form of use-site variance annotation, in contrast with the definition-site variance annotations found in C# and Scala.

  1. ^ "Chapter 4. Types, Values, and Variables". docs.oracle.com. Retrieved 2020-11-03.
  2. ^ Bloch 2018, pp. 117–122, Chapter §5 Item 26: Don't use raw types.
  3. ^ Gilad Bracha (June 2004), "4. Wildcards", Generics in the Java Programming Language (PDF), retrieved 6 March 2016
  4. ^ "8.1.2 Generic Classes and Type Parameters", The Java Language Specification, Oracle, retrieved 6 March 2016