What does <> mean for java generics?

后端 未结 2 1209
挽巷
挽巷 2020-12-05 23:19

I have a bit of code:

class MyClass 
  private List allPreExistingConfigsForCodes() {
    if(this.allCodesForThisType.size() == 0)
             


        
相关标签:
2条回答
  • 2020-12-05 23:30

    From the Java Tutorials generics lesson:

    In Java SE 7 and later, you can replace the type arguments required to invoke the constructor of a generic class with an empty set of type arguments (<>) as long as the compiler can determine, or infer, the type arguments from the context. This pair of angle brackets, <>, is informally called the diamond. For example, you can create an instance of Box<Integer> with the following statement:

    Box<Integer> integerBox = new Box<>();

    0 讨论(0)
  • 2020-12-05 23:45

    Are you using Java 7? If so, it is trying to take advantage of the new "diamond notation."

    http://docs.oracle.com/javase/tutorial/java/generics/genTypeInference.html#type-inference-instantiation

    0 讨论(0)
提交回复
热议问题