Inquisitive Inquisitive - 5 months ago 23
Java Question

What does "qualified this" construct mean in java?

In Effective Java inside the item "Item 22: Favor static member classes over nonstatic" Josh Bloch says:

Each instance of a nonstatic member class is implicitly associated with an
enclosing instance of its containing class. Within instance methods of a nonstatic
member class, you can invoke methods on the enclosing instance or obtain a reference
to the enclosing instance using the qualified this construct.

What does he mean by Qualified This Construct?


Without the qualifier, x() would recurse. With the qualifier, the enclosing instance's x() method is invoked instead.

class Envelope {
  void x() {
  class Enclosure {
    void x() {
      Envelope.this.x(); /* Qualified*/