The wildcard ? in generics represents an unknown type and accepts only null.
However, in the following example, the constructor accepts (for example) a String object, even though I have declared an instance of Test<?>.
public class Test<T> {
private T object;
public Test(T object) {
this.object = object;
}
public void set(T object) {
this.object = object;
}
public static void main(String[] args) {
Test<?> test = new Test<>("Test"); // compiles fine
//test.set("Test"); // compiler error
} …Run Code Online (Sandbox Code Playgroud)