This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm trying to use an Array and inovke its method calls but I keep getting "cant find symbol" errors. In looking at the java API I can see that there is an Array class and an Arrays class. When I create an array like this - private int someArray = new int; what class of array am I calling?
Shelby Simpson wrote:When I create an array like this - private int someArray = new int; what class of array am I calling?
To find out the class of an object, use the getClass() method. You will find that you are creating neither an "Array" or "Arrays" object.
This prints out "class [I". Similarly, [B is the class of the byte array, [C is the class of the char array, etc.
Shelby Simpson wrote:In looking at the java API I can see that there is an Array class and an Arrays class.
Oracle's website explains that these classes "contain various methods for manipulating arrays." To use the methods of these classes with your array, you must make a static reference to the class and pass in your existing array. For example:
Joined: Feb 17, 2013
Ok I see, I was looking at that all wrong. I didn't know about the getClass method. Thanks for clearing that up for me.