java - Diamond operator for return value -


Does it work with Java 7 ? (I just have Java 6 installed.)

  list & lt; & Gt; Customers = service.getCustomers (); // gives the list & lt; Customers & gt;   

Thanks.

No, the boilerplate code is used to avoid the diamond, twice by the generics:

Java 6:

  list & lt; List & lt; String & gt; & Gt; MyList = new array list & lt; List & lt; String & gt; & Gt; ()   

Java 7 equivalent:

  list & lt; List & lt; String & gt; & Gt; MyList = new ArrayList & lt; & Gt; () // means that the generic is the same one which is on the left of the declared declaration   

but in your example Diamond Operator declares to accept the "original generic" type correctly, So it will not be compiled.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -