Article Directory
Construction method introduction
构造方法(构造器)
创建对象的时候,要执行的方法
格式
1、方法名与类名相同,大小写也需要一致
2、没有返回值类型,连void
都没有
3、没有具体的返回值(不能由return
语句带回结果数据)
构造方法的执行时机
在创建对象的时候,被调用执行
每创建一次对象,就会执行一次构造方法构造方法的作用
1、本质的作用: 创建对象
2、结合执行时机: 可以创建对象的时候,给对象中的数据初始化
构造方法的注意事项
1、一个类中,没有编写构造方法,系统将会提供一个[默认的][无参数]的构造方法
2、一个类中,如果手动编写了构造方法,系统将不会再提供那个默认的无参构造了
建议: 编写类的时候,无参构造,带参构造,全部手动给出
3、构造方法不允许手动调用
Shortcuts for creating empty and parameterized constructors
first step
Right-click where you need to create a construction method to open the operation panel and select
Generate
OpenGenerate
Panel.
second step
Generate
SelectConstructor
Open Panel after openingChoose Fields to Initialize by Constructor
the panel.
third step
After opening
Choose Fields to Initialize by Constructor
the panel, clickSelect None
the button to create a parameterless constructor.
the fourth step
After opening
Choose Fields to Initialize by Constructor
, select the required parameters in the panel, and clickOK
the button to create a construction method with parameters.
Create shortcuts for get and set functions of member variables
first step
Right-click on the line where the construction method needs to be created to open the operation panel and select
Generate
OpenGenerate
Panel.
second step
Once the panel is open
Generate
, selectGetter and Setter
OpenSelect Fields to Generate Getters and Setters
Panel.
third step
After opening
Select Fields to Generate Getters and Setters
the panel, select the member variables that need to be createdget
andset
methods, and clickOK
.
Generate required content using plugins
first step
Click Open Dashboard
IDEA
in the upper left cornerFile
and selectSettings
OpenSettings
Dashboard.
second step
Once the panel is open
Settings
, selectPlugins
OpenPlugins
Panel.
third step
Plugins
The panel has two tabs, and the right tab lists the installed plug-ins.
the fourth step
Click the tab on the left, enter in the input box
ptg
, after searching for the plug-in, clickInstall
the option to install the plug-in.
the fifth step
After installing the plugin, click
OK
it.
step six
Right-click where the content is needed to open the operation panel and click
Ptg To JavaBean
to create content.