static 方法能在哪里定义
在写代码的时候,忽然想在类中实例化一个事件监听器的时候添加一个静态方法,提示如下错误:
static methods can only be declared in a static or top level type
静态方法只有在顶层类或者在在静态内部类中定义.
从网上找了段代码,
public class Test {
static void t(){}
class T2{
//!错误,The method a cannot be declared static;
//static methods can only be declared in a static or top level type
//static void a(){}
}
static class T3{
static void a(){}
}
}