简体   繁体   中英

Changing outer class reference for an object of inner class

I want to know is there any way I can change outer class reference associated with non-static inner class. eg In below code can I change outer class reference of i to point to o and not o1 ?

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class outer {
    public class inner {
    };
}
class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here


        outer o1 = new outer(), o = new outer();
        outer.inner i = o1.new inner();
        //i.outer.this = o;
    }
}

Thanks in Advance

No. Every inner class instance has an implicit reference to its containing outer class instance. If you want to change the relationships between these classes you might be better off extracting the inner from the outer class and having them depend on each other explicitly as normal classes do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM