Synopsis: | Use short array initializers without repeated type information |
Language: | Java |
Severity Level: | 6 |
Category: | TypeResolution |
Description: |
When declaring and initializing array fields or variables, it is not necessary to explicitly create a new array using new. Instead one can simply define the initial content of the array as a expression in curly braces.
int[] x = new int[] { 1, 2, 3 }; // overly verbose int[] x = { 1, 2, 3 }; // equivalent to the previous line |