This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Someone will probably explain it better than me, but, as your program shows the type of an array that contains ints is [I. An array of a different primitive type will be of a different type. And the type of an array of objects will be [L<class name>; For example, an array of Strings will be of type [Ljava.lang.String;
Try a few different array types in your program to see what I mean.
Okey but exactly which class is it? I searched all over the internet but couldnt find it. Doesnt java specification state where Arrays originate from. I know when you call getClass on an int array you get [I. What is this exactly?
Oceana Wickramasinghe wrote:Okey but exactly which class is it? I searched all over the internet but couldnt find it. Doesnt java specification state where Arrays originate from. I know when you call getClass on an int array you get [I. What is this exactly?
This is what Joanne stated in previous post:
[ - Is java's way of telling the JVM that the type for the variable is an array.
So when [L is used it means that the array is of some instances of some class and the class name follows [L
[I - Means an array of ints and int is not a class so it has a different representation.
Arrays is another class in Java, but that's used for a different purpose:
This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.
So arrays are themselves objects but they dont really represent any class unlike for example a List instance can be of ArrayList/Vector type.
Joined: Aug 05, 2005
Oceana Wickramasinghe wrote:I know when you call getClass on an int array you get [I. What is this exactly?
[I is the name of the class. I would imagine the lack of information about array classes is due to the fact that they are an internal implementation feature of the JVM. By not publishing information about how they are implemented the implementation can be changed without causing any problems. All you need to know about an array is that it is a fixed size, it has a final variable called length which gives you its length and it can only contain data of the declared type.