What the different between form ".this" and ".class"?

B

Bruce Sam

Here ".class" not means the class file.For example,in
"String.class.toString();".What does the ".class" and ".this" means?
 
R

Ryan Stewart

Bruce Sam said:
Here ".class" not means the class file.For example,in
"String.class.toString();".What does the ".class" and ".this" means?
The .class is kind of like a static member that isn't really there. It's a
shortcut to String's Class object. Same result as
Class.forName("java.lang.String").

And what do you mean ".this"? "this" is a keyword which is a reference to an
instance of the class you're coding. When dealing with nested classes,
".this", IIRC, can get you the reference to the enclosing instance.
 
S

Starshine Moonbeam

Here ".class" not means the class file.For example,in
"String.class.toString();".What does the ".class" and ".this" means?

this.
means this particular instance of a variable.

int something = 0;
int i = 3;

public void setSomething(int i) {

this.something = i;

}

Your something, that was initialized to zero, is now set to 3.

something = 2;
is the same as
this.something = 2;

return something;
is the same as
return this.something;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top