I know this
refers to the current object. I am little confused about this.ClassName
and ClassName.this
when creating Intent
.

- 55,782
- 14
- 81
- 108

- 288
- 6
- 21
-
What is ClassName? – Tim Aug 11 '17 at 14:19
-
1Possibly related to `ClassName.this`: [Getting hold of the outer class object from the inner class object](https://stackoverflow.com/questions/1816458/getting-hold-of-the-outer-class-object-from-the-inner-class-object) – Pshemo Aug 11 '17 at 14:21
-
public class LoginPage{} – Avinash Kumar Aug 11 '17 at 14:22
3 Answers
I am little confused about
this.ClassName
andClassName.this
when creating Intent.
The Classname.this
syntax is used to refer to an outer class instance when you are using nested classes; see Using "this" with class name for more details.
However this.Classname
is a compilation error ... unless you have declared an instance (or static) field with the name Classname
. (That would be a daft thing to do, as well as being an egregious style violation.)

- 698,415
- 94
- 811
- 1,216
Intent intent=new Intent(context, AcitivityName.class);
The first argument is just the context so when you write for ex. Main.this you are just referring to the context of that activity.
The second argument is the a Activity you want to start or whatever...

- 313
- 1
- 12
I'm assuming ClassName is just filling in for the current class's name. ClassName.this is exactly the same as simply writing this. So if a class had a variable called foo you could reference it from that class using ClassName.this.foo the same way you could with this.foo.
this.ClassName is not valid java as far as I know.

- 560
- 5
- 18