I referred to documentation on Java Generics, and trying to use the wildcard "?" in a simple program:
class Unknown <?> {
}
public class UnknownTypes {
public static void main(String s[] ) {
}
}
Wildcard "?" refers to an Unknown type, so in class Unknown, I used type-parameter wildcard itself; however when I compile I get compilation error. If I had used like this it would have worked.
class Unknown <T> {
}
If wildcard "?" refers to unknown type, why can't we use "?" as type parameter.
The following is the compile error that I get.
UnknownTypes.java:1: error: <identifier> expected
class Unknown <?> {
^
UnknownTypes.java:1: error: '{' expected
class Unknown <?> {
^
UnknownTypes.java:10: error: reached end of file while parsing
}
Is wildcard "?" used in conjunction with something else?