java enum in class_Java 8需要一个转换,而Java 7没有 – enum.getClass/getDeclaringClass
我意識到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還是新功能?
總結
以上是生活随笔為你收集整理的java enum in class_Java 8需要一个转换,而Java 7没有 – enum.getClass/getDeclaringClass的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 锐龙6000新版拯救者R7000P/R9
- 下一篇: 通用返回_Springboot项目整合通
