The following is a quote from Sun tutorial on reflection API.
If you know the name of the class at compile time, you can retrieve its Class object by appending .class to its name. In the next example, the Class object that represents the Button class is retrieved:
What's the mechanism behind appending the word class with the name of the class? How does that work? Thanks.
------------------ Velmurugan Periasamy Sun Certified Java Programmer ---------------------- Study notes for Sun Java Certification http://www.geocities.com/velmurugan_p/
------------------------------------------------------------------------------------<BR>Velmurugan Periasamy<BR>Sun Certified Java Programmer for Java 2 Platform<BR>Sun Certified Web Component Developer for J2EE platform<BR>Sybase Certified EAServer Developer (similar to jCert level 3)<BR>------------------------------------------------------------------------------------<BR>Study notes for Sun Java Certification<BR><A HREF="http://www.geocities.com/velmurugan_p/" TARGET=_blank rel="nofollow">http://www.geocities.com/velmurugan_p/</A><BR>------------------------------------------------------------------------------------
That's called a class literal - it's part of the language specification, right here. Basically that means that any Java compiler is required to recognize that if I type "Frame.class" for example, it should substitute a reference for the Class object representing a Frame. Much the way if I type a string literal enclosed in quotes, the compiler will interpret that as a reference to a String object.
"I'm not back." - Bill Harding, Twister
Velmurugan Periasamy
Ranch Hand
Joined: Nov 09, 2000
Posts: 95
posted
0
Thanks Jim. ------------------ Velmurugan Periasamy Sun Certified Java Programmer ---------------------- Study notes for Sun Java Certification http://www.geocities.com/velmurugan_p/