IDEA automatically generates Java Bean-construction method and get and set methods

What is Java Bean?

A standard class usually has four components:

  • 1. All member variables need to be modified with the private keyword.
  • 2. Write a pair of Get/Set methods for each member.
  • 3. Write a no-argument constructor for the class.
  • 4. Write a parameter construction method for the class. (All parameters)

How the IDEA editor uses shortcut keys to automatically generate construction methods

  1. According to the process, a class named sudent is generated, which contains two member variables, and both member variables need to be modified by the private keyword.Insert picture description here
  2. Shortcut key (Alt+Insert) generates no-parameter construction method
    Select the sudent class:
    Insert picture description here
    Press the shortcut key Alt+Insert to get the following interface:
    Insert picture description here
    select the blue class student:Insert picture description here
    Insert picture description here
  3. Shortcut key (Alt+Insert) to generate full parameter construction method
    is similar to the above: the key point is to select student and all member variables after holding down Shift:
    Insert picture description here
    Insert picture description here
  4. (Alt+Ins) Generate member method:
    select member variable (name):
    Insert picture description here
    Alt+Ins shortcut key to get the following interface:
    Insert picture description here
    select the member variable name:
    Insert picture description here
    finally get the get and set methods: the
    Insert picture description here
    same way you can get the get/ of the member variable age set method:
    Insert picture description here

Guess you like

Origin blog.csdn.net/wscffaa/article/details/103254533