简体   繁体   English

java方法本地内部类

[英]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. 在这里,我想传递给同一类MethodClass或该类之外的任何其他函数。 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. 我不能说我曾经使用过方法本地类声明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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