[Graphic tutorial] One of the usage that eclipse cannot know: automatically generate getter, setter, and constructor

Source: Internet
Author: User

Key words: getters and setters, getter and setter methods, constructor using fields, constructor, eclipse-jee usage, Automatic GenerationCodeEclipse3.5, graphic tutorial

(1) The pojo class automatically generates the getter and setter methods:

Persion. Java original code:

Right-click the blank area of the code above, or right-click the person class name-> source-> Generate getters and setters, for example:

Then, in the generate getters and setters dialog box, hook the persion attribute ID and name, or directly click "select all" to select all attributes, and click OK.

Let's take a look at the person. Java class code:

It can be seen that the getter method and setter method are automatically generated, which is much easier than tapping the code one by one.

 

 

(2) automatically generate the constructor (constructor ):

Right-click the blank area of the class code, or right-click the class name-> source-> Generate constructor using fields, for example:

In the generate constructor using Fields dialog box, hook all or some attributes of the persion class, and click OK. For example:

Next, let's take a look at the self-generated constructor. See the selected section:

Related Article

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.