简体   繁体   中英

java method local inner class

i am trying to pass method local inner class object as an argument to some other function either in the scope of outside class or out of that class

public class MethodClass {
public void p(){
    class h{
        public void h1(){
            System.out.print("Java Inner class");
        }
    }
    h h2=new h();
}
}

here h2 i want to pass to any other function in the same class MethodClass or out of that class. can any one give me the procedure to pass the argument in that way?

If another method needs to know about the class, then you shouldn't declare it within a method, basically. Make it a nested class within the class itself, or even a top-level class.

I can't say I've ever used method-local class declarations.

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