静态内部类的使用
@Data public class Teacher { private Integer age;private String name; // 内部类的成员变量private Teacher.Student student; // 这个是内部接口的使用方法public Teacher(){this.student = new Student();}/*** 静态的类*/static class Student{void show(){System.out.println("我爱你");}} }
public static void main(String[] args) {// 创建一个内部静态对象Student student = new Teacher.Student();student.show();}
非静态内部类的使用
@Data public class Teacher { private Integer age;private String name;private Teacher.Student student; // 这个是内部接口的使用方法public Teacher(){this.student = new Student();}/*** 静态的类*/class Student{void show(){System.out.println("我爱你");}}
public static void main(String[] args) {Teacher teacher = new Teacher();Student student = teacher. new Student(); // 这里创建一个对象student.show();}