Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8288471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:17:24+00:00 2026-06-08T12:17:24+00:00

Following is from Effective Java: The association between a nonstatic member class instance and

  • 0

Following is from Effective Java:

The association between a nonstatic member class instance and its enclosing
instance is established when the former is created; it cannot be modified
thereafter. Normally, the association is established automatically by invoking a
nonstatic member class constructor from within an instance method of the
enclosing class. It is possible, although rare, to establish the association manually
using the expression enclosingInstance.new MemberClass(args). As you
would expect, the association takes up space in the nonstatic member class
instance and adds time to its construction.

What is Bloch saying here by “It is possible, although rare, to establish the association manually using the expression enclosingInstance.new MemberClass(args). As you would expect, the association takes up space in the nonstatic member class instance and adds time to its construction.” ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:17:25+00:00Added an answer on June 8, 2026 at 12:17 pm

    He means you can establish the connection in at least two ways. Given

    public class Outer {
        public class Inner {
        }
        void f() {System.out.println(new Inner());}
    }
    Outer x = new Outer();
    

    If you call

    x.f()
    

    then the value you print is an inner object linked to x.

    But one can also invoke:

    x.new Inner();
    

    to create a new inner object linked to x as well.

    Bloch is saying the second way is rare. I’m not sure why; I have used it in the past.

    See a live demo

    class Outer {
        String name;
        public Outer(String name) {
            this.name = name;
        }
    
        public class Inner {
            public String toString() {
                return "I belong to " + Outer.this.name;
            }
        }
    
        void f() {
            System.out.println(new Inner());
        }
    
        void g(Outer a) { 
            System.out.println(a.new Inner());
        }
    }
    
    class Main {
        public static void main(String[] args) {
            Outer x = new Outer("x");
            Outer y = new Outer("y");
            x.f();
            x.g(y);      
        }
    }
    

    Output:

    I belong to x
    I belong to y
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following from Effective Java Item 11 (Override clone judiciously) where Josh Bloch
I am trying to fathom the following lines from Effective Java One thing that
I read from Effective Java that In the absence of synchronization the following sequence
Item 16 of Effective Java 2nd edition, favor composition over inheritance says the following
I am reading about double check locking from Effective Java . The code does
The following code snippet is from book Effective C#, public event AddMessageEventHandler Log; public
From Effective Java ( Chapter 10 Concurrency ) Suppose you were to invoke an
Following from this: Every specific weekday, sql and php I got this: deals_bookings.everyWeekDay =
Following from my last question which @Jon Skeet gave me a lot of help
Following from these question Subset sum problem and Sum-subset with a fixed subset size

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.