A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/1495 below:

[java] Rule to detect overly verbose array initializiation · Issue #1495 · pmd/pmd · GitHub

E.g.

Foo[] x = new Foo[] { ... };

can be written equivalently as

Also,

Foo[] x = new Foo[0];
// can be rewritten to 
Foo[] x = {}; // I think this should probably be opt-out, since new Foo[0] is very readable 

This is only possible in local variable or field declaration initializers, in all other contexts, the new Foo[] is mandatory. E.g. the following is disallowed:

The rule would belong in the code style category.

I read on stackoverflow that this lighter syntax is not from the original Java 1.0 spec but probably from 1.1, but we don't have language versions below 1.3 anyway. Recent JLS: https://docs.oracle.com/javase/specs/jls/se8/html/jls-10.html#jls-10.6


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4