目录
异常信息:
No enclosing instance of type LamdaTest is accessible. Must qualify the allocation with an enclosing instance of type LamdaTest (e.g. x.new A() where x is an instance of LamdaTest).
报错源代码:
public class LamdaTest {
@data
class People{
private String name;
private Integer age;
}
public static void main(String[] args) {
People p1 = new People();//报错位置
p1.setName("aaa");
p1.setAge(23);
}
}
报错原因:
main方法是一个静态方法,而内部类People是一个非静态的类,所以在main方法中不能访问;
解决办法:
1、将内部类挪出去写成正常的外部类;
2、将内部类改成静态内部类;