为即将开始的项目进行类型转换,我意外地发现了这个错误:
incompatible types: Class cannot be converted to myObj
where CAP#1 is a fresh type-variable:
CAP#1 extends ImyObj from capture of ? extends ImyObj
导致此错误的代码:
ImyObj testObj = new myObj();
System.out.println(testObj.sayHi());
myObj testObj2 = (testObj.getClass()) testObj;
System.out.println(testObj2.sayBye());
但是这很好用:
ImyObj testObj = new myObj();
System.out.println(testObj.sayHi());
myObj testObj2 = (myObj) testObj;
System.out.println(testObj2.sayBye());
难道他们不应该做同样的事情,或者我错过了什么?我目前安装了Java 1.7_51.我已经有一段时间了,因为我沉浸在Python 2.7中,因此我接触了Java(1.7之前).
编辑:
Louis Wasserman的回答也提出了同样的错误.