DEV Community

Pramod Bablad
Pramod Bablad

Posted on

1

Java 9 Diamond Operator Improvements

Diamond Operator : Before Java 7

Before Java 7, you need to explicitly mention type on both side of the declaration statement.

List list = new ArrayList();
Set set = new HashSet();
Map map = new HashMap();

Diamond Operator : After Java 7

With the introduction of empty diamond operator <> from Java 7, you need not mention type on the right side of the declaration statement. You can leave empty inside the diamond operator. Java compiler automatically determines the type on the right side of the declaration statement.

List list = new ArrayList<>();
Set set = new HashSet<>();
Map map = new HashMap<>();

But, that rule doesn’t apply to anonymous inner classes. Empty diamond operator can not be used with anonymous inner classes.

This issue has been resolved from Java 9.

From Java 9, you can use empty diamond operator <> for anonymous inner classes also.

Source : https://javaconceptoftheday.com/java-9-diamond-operator-improvements/

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay