Lombok (1.14.8)-@Getter, @Setter, @ToString, @EqualsAndHashCode & @Data

Source: Internet
Author: User

@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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.