This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What King of Class is a Array?

 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

i want to know something...

What King of Class is a Array? I mean a variable with the [].

I clarify my question with the next example:



But if I want to test this array (a) exactly with the kind of Class of this kind (Array)?

Somebody know?

Thankyou.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can test

For a primitive type array, that's really the only thing that would apply. For a reference type array, you could also test arrays of supertypes, e.g.
 
Rob Spoor
Sheriff
Pie
Posts: 20380
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two ways.

One is to test if an object is an array of any type:

The second one can be used if you want to test for a specific type of array:

This works because all arrays are objects themselves, and so they can be used wherever objects can be used.
Similarly, just as you can use Object.class or String.class to get the Class object for "String", you can use int[].class to get the Class object for "array of int", and even complex stuff like String[][][].class.
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the fast answer.

Thank you Jim Yingst and Rob Prime
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic