• Post Reply Bookmark Topic Watch Topic
  • New Topic

The keywork class  RSS feed

 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi rancher,

sometimes when I see a source code, I see the .class keywork, por example MyClass.class, I want to know what is the use of this.

If someone can giveme pages that talk about this, will awesome.

Thank you in advance.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I think you meant "keyword", as per http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#251530.)

It just returns the java.lang.Class.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to what David said, it returns the same Class object as this piece of code:
The advantage of using MyClass.class is that you don't need to create an instance of the class first.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Milton Ochoa wrote:Hi rancher,

sometimes when I see a source code, I see the .class keywork, por example MyClass.class, I want to know what is the use of this.

If someone can giveme pages that talk about this, will awesome.

Thank you in advance.


it give the name of class

and also if you use getclass().getName().toString();

it will take the object of the class and then with the help of that object it will get its name......and then convert that into a string..........
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not the same. getClass() returns a Class object. getClass().getName() returns a String object. The final toString() is even useless since it returns the exact same String.
 
salvin francis
Bartender
Posts: 1653
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys
I think she/he is probably refering to the extension as to why is it .class file ?

Milton Ochoa wrote:MyClass.class, I want to know what is the use of this
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think so, since they were asking about "in source code".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!