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, b ends referring same array a, aside caveats below.)
  • if a null, first 1 throw nullpointerexception.
  • if you're unlucky, first 1 throw outofmemoryerror or similar.
  • the first 1 more cause compiler warnings, findbugs warnings, etc.

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -