[英]Why can't i have an access specifier in a method local Inner class?
Why Method Local Inner class cannot be public? 为什么方法本地内部类不能公开? I know it is useless to make them private but why not public? 我知道将它们私有化是没用的,但为什么不公开呢? Is that because Method Local Inner is also treated as local variables? 那是因为Method Local Inner也被视为局部变量吗? As local variables cannot be public. 由于局部变量不能公开。 Am i going right or missing something? 我是对的还是错过了什么?
public class OuterClass {
public void outerMethod() {
public class Inner { // having problem here
...
}
}
}
Since it is declared within the method body, ie. 因为它是在方法体内声明的,即。 it's a local class, you can't refer to it by name anywhere else in your code, only in the method body itself following its declaration. 它是一个本地类,你不能在代码中的任何其他位置引用它,只能在声明后的方法体本身中引用它。 It is therefore pointless for it to have an access modifier. 因此,它具有访问修饰符是没有意义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.