Re: Trying to create a working internal confirm JOptionPane



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
.



Relevant Pages

  • Re: Need a way for forgetful developers
    ... Almost every developers define classes and use them in anothers. ... If A is a class and B uses A then we can name B as outer class and A as inner class. ... In its initialize method, outer class should call the initialize method of every inner class objects, ...
    (microsoft.public.vc.language)
  • Re: Updating GUI & Running Program (AND accessing common variables!)
    ... >> outer class from the inner class, I get a compile error that says I can't ... > You need to clarify what you mean by 'in the outer class'. ... > make a long story short, an anonymous inner class can only access local ... Okay, let me rephrase, to make sure I understand this correctly. ...
    (comp.lang.java.gui)
  • Re: Want - but cannot get - a nested class to inherit from outer class
    ... dict dictA: ...   dict membB: ... AM DEFINING METHODS on the inner class. ... proceed with the outer class being the inner class' parent. ...
    (comp.lang.python)
  • Re: Updating GUI & Running Program (AND accessing common variables!)
    ... >>You need to clarify what you mean by 'in the outer class'. ... >>An anymous inner class relies on some compiler magic. ... >>copies the values of all local variables into corresponding variables of ... an anonymous inner class can only access local ...
    (comp.lang.java.gui)
  • Re: Updating GUI & Running Program (AND accessing common variables!)
    ... >anonymous inner class cannot access variables from the outer class unless ... >have no problem accessing the variables in the outer class. ... Finalize is not the same as final. ... have local variables. ...
    (comp.lang.java.gui)