Re: Trying to create a working internal confirm JOptionPane
- From: Lew <lew@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Feb 2007 10:41:54 -0500
phillip.s.pow...@xxxxxxxxx wrote:
Why do I use OuterClass.this? Isn't that calling the outerclass
statically? I simply do not understand, even in spite of the
tutorials I don't get it.
Lew wrote:
In an inner class, "this" by itself points to the inner class instance. The
inner class, because it is an inner class, belongs to an object of the outer
class. That means there is an outer class "this", and the language
specification says that to obtain a reference to the outer class instance, the
syntax is
Foo.this
where Foo is the outer class.
This is a matter of language syntax. Just because it looks like a static
reference doesn't make it one. "this" is a keyword, not a variable name.
phillip.s.powell@xxxxxxxxx wrote:
You completely lost me.
I am saying that "this" is a keyword with a few different rules, and that you cannot confuse one rule with the other.
You are talking about a core Java concept, the keyword "this", the understanding of which is fundamental to using Java. You should know the rules for the keyword.
There are three usages.
- a reference to the instance itself, as in "this.value = value;"
- as the first line of a constructor, the invocation of another constructor in the class, as in
public Foo()
{
this( DEFAULT );
}
- as a reference to the instance of an outer class that owns this inner class, the topic of your question. This last one is more advanced than the other two.
Your confusion came from seeing case #3 as similar to a static variable reference. It is not a static variable reference, but a completely different part of the Java language. Your mistake was thinking that one part of the Java language should follow rules from another part.
- Lew
.
- Follow-Ups:
- Re: Trying to create a working internal confirm JOptionPane
- From: phillip.s.powell@xxxxxxxxx
- Re: Trying to create a working internal confirm JOptionPane
- References:
- Trying to create a working internal confirm JOptionPane
- From: phillip.s.powell@xxxxxxxxx
- Re: Trying to create a working internal confirm JOptionPane
- From: Andrew Thompson
- Re: Trying to create a working internal confirm JOptionPane
- From: phillip.s.powell@xxxxxxxxx
- Re: Trying to create a working internal confirm JOptionPane
- From: Daniel Dyer
- Re: Trying to create a working internal confirm JOptionPane
- From: phillip.s.powell@xxxxxxxxx
- Re: Trying to create a working internal confirm JOptionPane
- From: Daniel Dyer
- Re: Trying to create a working internal confirm JOptionPane
- From: phillip.s.powell@xxxxxxxxx
- Re: Trying to create a working internal confirm JOptionPane
- From: Lew
- Re: Trying to create a working internal confirm JOptionPane
- From: phillip.s.powell@xxxxxxxxx
- Trying to create a working internal confirm JOptionPane
- Prev by Date: Testing for a User in a Session (JSP/Servlet)
- Next by Date: Re: no autoexec.bat
- Previous by thread: Re: Trying to create a working internal confirm JOptionPane
- Next by thread: Re: Trying to create a working internal confirm JOptionPane
- Index(es):
Relevant Pages
|