Eclipse设置Instance variable的前缀

本文介绍如何在Eclipse中设置代码样式偏好,通过指定变量前缀来自动生成合适的Getter和Setter方法,特别是对于布尔类型的变量使用'is'前缀。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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().

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值