• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What King of Class is a Array?

 
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the fast answer.

Thank you Jim Yingst and Rob Prime
 
reply
    Bookmark Topic Watch Topic
  • New Topic