• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question on reflection

 
Velmurugan Periasamy
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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/
 
Velmurugan Periasamy
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, The above quote is taken from the following URL:
http://java.sun.com/docs/books/tutorial/reflect/class/getClass.html
Thanks.
------------------
Velmurugan Periasamy
Sun Certified Java Programmer
----------------------
Study notes for Sun Java Certification
http://www.geocities.com/velmurugan_p/
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Velmurugan Periasamy
Ranch Hand
Posts: 95
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jim.
------------------
Velmurugan Periasamy
Sun Certified Java Programmer
----------------------
Study notes for Sun Java Certification
http://www.geocities.com/velmurugan_p/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic