我得到以下编译消息:
[javac] ... error: incompatible types
[javac] exceptionClassHolder = new Holder<>( (new Exception()).getClass() );
[javac] ^
[javac] required: Holder>
[javac] found: Holder>
[javac] where CAP#1 is a fresh type-variable:
[javac] CAP#1 extends Exception from capture of ? extends Exception
[javac] 1 error
在我看来,根据消息一切都应该是正确的. CAP#1确实扩展了异常.那么上述消息应该如何理解呢? SSCCE下面(最初没有发布,因为我希望在一般情况下了解错误消息本身):
class Holder {
public T t;
public Holder(T t) {
this.t = t;
}
}
public class FooMain {
public static void main(String args[]) throws Exception {
Holder> exceptionClassHolder;
exceptionClassHolder = new Holder<>( (new Exception()).getClass() );
}
}