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

Question

What is the output of the following code?

public class Main {
  public static void main(String[] args) {
    Wrapper<?> stringWrapper = new Wrapper<String>("Hello");
    Object str = stringWrapper.get(); 
    System.out.println(str);
  }
  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

H:Note

The compiler knows that the get() method of the Wrapper<T> class returns an object of type T.

For the unknownWrapper variable, type T is unknown.

The following statement will not throw a ClassCastException at runtime.

Object str = stringWrapper.get();

No matter what type of object the get() method returns, it will always be assignment-compatible with the Object type.