java - Is there a difference between int[] b = new int[a.length] b=a and int[] b = a? -
is there difference between
int[] b = new int[a.length]; b=a; and
int[] b = a; in java?
they're same, there few differences:
- in general, first 1 create array becomes unreachable (eligible garbage collection), not exist. (in both versions,
bends referring same arraya, aside caveats below.) - if
anull, first 1 thrownullpointerexception. - if you're unlucky, first 1 throw
outofmemoryerroror similar. - the first 1 more cause compiler warnings, findbugs warnings, etc.
Comments
Post a Comment