Eclipse设置Instance variable的前缀

来源:互联网 发布:淘宝巨型猪笼草 编辑:程序博客网 时间:2024/04/27 03:00
Generating getters and setters
The first step is to configure Eclipse to recognize the m prefix for member variables and to use is
rather than get for boolean variables.
Open Eclipse’s preferences (from the Eclipse menu on Mac and from Windows → Preferences on
Windows). Under Java preferences, select Code Style.
In the Conventions for variable names: table, select the Fields row (Figure 2.3). Click the Edit button
and add m as a prefix for fields. Then add s as a prefix for static fields. (You will not be using the s
prefix in the GeoQuiz project, but it will be useful in later projects.)
Make sure the Use ‘is’ prefix for getters that return boolean is checked. Then click OK.

Figure 2.3 Setting Java code style preferences

What is the point of setting these prefixes? Now when you ask Eclipse to generate a getter for
mQuestion, it will create getQuestion() rather than getMQuestion() and
isTrueQuestion() rather than isMTrueQuestion().