@Getter/@Setter
The Gette R and Setter methods are implemented @Getter and @Setter respectively.
PackageCom.huey.hello.bean;Importjava.util.Date;ImportLombok. Getter;ImportLombok. Setter; Public classStudent {@Getter @SetterPrivate intStudno; @Getter @SetterPrivateString Studname; @Getter @SetterPrivateDate birthday; Public Static voidMain (string[] args) {Student stud=NewStudent (); Stud.setstudname ("Huey"); System.out.println (Stud.getstudname ()); //[OUTPUT]: Huey }}
@ToString
@ToString, the ToString () method is implemented.
PackageCom.huey.hello.bean;Importjava.util.Date;ImportLombok. Getter;ImportLombok. Setter;ImportLombok. ToString; @ToString Public classStudent {@Getter @SetterPrivate intStudno; @Getter @SetterPrivateString Studname; @Getter @SetterPrivateDate birthday; Public Static voidMain (string[] args) {Student stud=NewStudent (); Stud.setstudno (10001); Stud.setstudname ("Huey"); Stud.setbirthday (NewDate ()); SYSTEM.OUT.PRINTLN (stud); //[OUTPUT]: Student (studno=10001, Studname=huey, Birthday=fri Jul 23:01:56 CST) }}
@EqualsAndHashCode
@EqualsAndHashCode, the Equals () and Hashcode () methods are implemented.
PackageCom.huey.hello.bean;Importjava.util.Date;ImportLombok. Equalsandhashcode;ImportLombok. Getter;ImportLombok. Setter; @EqualsAndHashCode Public classStudent {@Getter @SetterPrivate intStudno; @Getter @SetterPrivateString Studname; @Getter @SetterPrivateDate birthday; Public Static voidMain (string[] args) {Student stud1=NewStudent (); Stud1.setstudno (10001); Stud1.setstudname ("Huey"); Stud1.setbirthday (NewDate ()); Student STUD2=NewStudent (); Stud2.setstudno (10001); Stud2.setstudname ("Huey"); Stud2.setbirthday (NewDate ()); System.out.println (Stud1.hashcode ()); //[OUTPUT]: -349449895System.out.println (Stud2.hashcode ());//[OUTPUT]: -349449895System.out.println (Stud1.equals (STUD2));//[OUTPUT]: True }}
@Data
@Data, quite the above three annotation.
PackageCom.huey.hello.bean;Importjava.util.Date;ImportLombok. Data; @Data Public classStudent {Private intStudno; PrivateString Studname; PrivateDate birthday; Public Static voidMain (string[] args) {Student stud1=NewStudent (); Stud1.setstudno (10001); Stud1.setstudname ("Huey"); Stud1.setbirthday (NewDate ()); Student STUD2=NewStudent (); Stud2.setstudno (10001); Stud2.setstudname ("Huey"); Stud2.setbirthday (NewDate ()); System.out.println (Stud1.hashcode ()); //[OUTPUT]: -349006373System.out.println (Stud2.hashcode ());//[OUTPUT]: -349006373System.out.println (Stud1.equals (STUD2));//[OUTPUT]: TrueSystem.out.println (STUD1);//[OUTPUT]: Student (studno=10001, Studname=huey, Birthday=fri Jul 23:13:43 CST) }}
Lombok (1.14.8)-@Getter, @Setter, @ToString, @EqualsAndHashCode & @Data