Java - What is the output: type of unknown type?

Question

What is the output of the following code?

public class Main {
  public static void main(String[] args) {
    Wrapper<Object> objectWrapper = new Wrapper<Object>(new Object());
    printDetails(objectWrapper); // OK

    Wrapper<?> stringWrapper = new Wrapper<String>("Hello");
    
    String str = stringWrapper.get(); // A compile-time error
    
    printDetails(stringWrapper); 

  }
  public static void printDetails(Wrapper<?> wrapper){
    System.out.println(wrapper);
  }
}

class Wrapper<T> {
  private T ref;

  public Wrapper(T ref) {
    this.ref = ref;
  }

  public T get() {
    return ref;
  }

  public void set(T a) {
    this.ref = a;
  }
}


Click to view the answer

String str = stringWrapper.get(); // A compile-time error

Note

stringWrapper is declared as unknown type.