我意识到Java 8仍然在测试版,但是这一点让我很奇怪:
public class Fields> {
public Fields(Set columns) {
// A sample column used to find the universe of the enum of Columns.
C sampleCol = columns.iterator().next();
// Java 8 needs a cast here.
Set allColumns = EnumSet.allOf((/*Class)*/ sampleCol.getClass());
// ... there's more to this that I've deleted.
}
}
错误读取:
error: incompatible types: inferred type does not conform to equality constraint(s)
Set allColumns = EnumSet.allOf(sampleCol.getClass());
inferred: C
equality constraints(s): C,CAP#1
where C is a type-variable:
C extends Enum declared in class Test.Fields
where CAP#1 is a fresh type-variable:
CAP#1 extends Enum from capture of ? extends Enum
这是Java 8的一个bug还是新功能?