Playing with the casting type for the project, Iām about to start, I unexpectedly found this error:
incompatible types: Class<CAP#1> cannot be converted to myObj
where CAP#1 is a fresh type-variable:
CAP#1 extends ImyObj from capture of ? extends ImyObj
The code that caused this error:
ImyObj testObj = new myObj();
System.out.println(testObj.sayHi());
myObj testObj2 = (testObj.getClass()) testObj;
System.out.println(testObj2.sayBye());
However, this works great:
ImyObj testObj = new myObj();
System.out.println(testObj.sayHi());
myObj testObj2 = (myObj) testObj;
System.out.println(testObj2.sayBye());
Don't they do the same or am I missing something? I currently have Java 1.7_51 installed. It has been a while since I touched Java (before 1.7) since I immersed myself in Python 2.7.
EDIT:
Louis Wassermann's answer also raises the same error.
source
share