网上优缺点:
public class Student{ private Long id; private String name; private int age; private int gender; public Long getId(){ return id; } public void setId(Long id){ this.id = id; } public String getName(){ return name; } public void setName(String name){ this.name = name; } public int getAge(){ return age; } public void setAge(int age){ this.age = age; } public int getGender(){ return gender; } public void setGender(int gender){ this.gender = gender; } @Override public boolean equals(Object o){ if(this == o){ return true; } if(o == null || getClass() != o.getClass()){ return false; } Student obj = (Student) o; return age = obj.age && gender = obj.gender && Objects.equals(id,obj.id) && Objects.queals(name,obj.name); } @Override public int hashCode(){ return Objects.hash(id,name,age,gender); } @Override public String toString(){ return "Student{"+ "id="+id+ "name="+name+ "age="+age+ "gender="+gander+ "}"; } }
使用注解后
@Data @Builder public class Student{ private Long id; private String name; private int age; private int gender; }
Lombok注解
但其实就我们项目而言,个人建议
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@NonNull
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)