View Single Post
Old 12-29-2011, 04:31 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
String[] is just the datatype, as is int[]. You don't need to specify the size of it until you instantiate it. When an array is returned by something different, it can take the place of the placeholder.
Simple look: T[] -> 4 byte pointer <- T[4] returned
The T[] you declared is simply a pointer to the returned results of the T[4]. The pointer has been assigned, but in Java world I don't know if its a direct memory pointer or if it has multiple levels of indirection. I'd assume multiple levels.

Your thread is different. String.split will return a String[], so you cannot just cast that into an int[] type. Without a defined size of the T[], it is assumed to be that of 0, so you cannot dereference it to write any data into it.
So with your example you could have actually used:
PHP Code:
String[] octets args.getHostAddress().split("\\."); 
The only way to cast it is by iterating it after the fact, which means you'll need to either do something immediately, store it in a collection, or use a pre-defined array size.

Edit:
Sorry, for a better explanation of the problem in your other thread:
int[] i = null; is an int array without a size. Your error came from trying to use i[value], since this would never exist. This is why you needed to use a new int[4] for the size.

Last edited by Fou-Lu; 12-29-2011 at 04:34 PM..
Fou-Lu is offline   Reply With Quote