Diamond operator feature was introduced in Java 7. Using of Diamond operator from Java 7 onwards there is no need to mention generic type on the right-hand side of the expression.
How to declare Diamond Operator in Java?
Problem with Diamond Operator while using Annonymous Inner class:
Until Java 8 Diamond Operator allow us to use in normal class only. This Diamond Operator is not allowed to anonymous inner class in Java.
Example:
Output:
Example.
We got a compilation error when we ran this above example until Java 8.
Java 9 - Diamond Operator Enhancement:
From Java 9 onwards Diamond Operator is allowed to use in anonymous classes also. This is the enhancement of Diamond Operator in Java 9.
Example:
Output:
Hello Programmer
Conclusion:
In this topic, we learnt about Diamond Operator in Java, Diamond Operator anonymous inner class problem until Java 8 and Diamond Operator enhancement in Java 9
|
Author: |
SpringJava |
|
Viewed: |
7 Views |
|
 |
 |
This Blog Has Been PowerShared™ Successfully! |
|
|
Check Out All Of 's Blogs! |
Comments: |
|
|