java - Legacy array notation not allowed on variable-arity parameter -
i'm asking out of curiosity have not found question specific compile error on stackoverflow:
legacy array notation not allowed on variable-arity parameter
i've come across legacy notation when seeing code containing signature this:
private void a(int ints[]){/*...*/}
so played arround bit until encountered compile error in following samples.
// method compiles expected private void method1(int[][] ints){ /*...*/ } // private void method2(int[]... ints){ /*...*/ } // to, makes use of legacy array notation private void method3(int ints[][]){ /*...*/ } // still does, when mixing notations private void method4(int[] ints[]){ /*...*/ } // fails compile private void method5(int... ints[]){ /*...*/ }
is there specific reason, language designer decided implement way? not allow varargs legacy array notation?
note: understand legacy notation
i don't know why decided this*, however, i'd confirm formal part of specification , intended produce compile-time error:
it compile-time error use mixed array notation (§10.2) variable arity parameter.
from jls 8.4.1
*that question opinion-based since no 1 besides java language designers tell you. if speculate, it's because allowing multiple notations in first place kind of bad idea.
Comments
Post a Comment