What does .class mean ?

gplana
gplana used Ask the Experts™
on
Hi.

I'm starting to program in Android. When using tabs, I have this line of code:

tabHost.addTab(tabHost.newTabSpec(i + "").setIndicator(names[i]), myClass.class, b);

Open in new window


What does the .class mean? Can I make an array of a set of classes with the .class? For example:
   myArray[0] = myClass.class;
   myArray[1] = myOtherClass.class;
etc... ?

Open in new window

In this case, which type should be declared this array?

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Every object in Java has one (and the same) class object associated with it. X.class refers to that class object connected to an instance of X
Senior Java Architect
Commented:
In this case, which type should be declared this array?

The .class value associated with every object is an instance of java.lang.Class, so you'd make an array using something like this:

Class<?>[] classes = new Class<?>[2];

Open in new window

Thanks, but what does <?> means? Whould I write these characters litarally?
CPColinSenior Java Architect
Commented:
The <?> has to do with a concept in Java called "generics." You probably don't have to start worrying about them quite yet. But yes, you'd type those characters in exactly as shown.
Great, thank you very much.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial