This is, perhaps, a stupid question, but I’ve found nothing on it elsewhere. I’m going through the basics of Android, and when I try to create an intent specifically to run another activity of my choosing, the tutorial tells me to construct it this way:
Intent intent = new Intent(this, DisplayMessageActivity.class);
Where “DisplayMessageActivity” is the class for the activity I’m running. What I don’t get is, what’s the “.class” part? That parameter, as I understand it, is supposed to be a Class object. Is “class” a field of my Activity subclass? Or when I say “DisplayMessageActivity.class”, am I referring to an actual .class file (that seems a little weird)?
Any help is appreciated!
While the
.classappears to be a normal field access, it is actually a special language construct, that is explained very well in the Retrieving Class Objects Java tutorial.It says, quote:
And they give the example:
In my day to day usage of Java, this isn’t a hugely used construct, and many are unaware of it. Generally it’s used with generics and the like when specificing classes in general rather than instances of them.
I hope this helps. 🙂