加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 可以IntelliJ生成没有“get”前缀的getter吗?

发布时间:2020-12-14 05:24:50 所属栏目:Java 来源:网络整理
导读:IntelliJ有一个很酷的功能来生成 Java getter.例如,对于一个字段private final String foo,它将生成一个getter getFoo(). 有没有办法配置IntelliJ以String foo()格式生成getter?我正在主要使用不可变对象,并喜欢这种语法. 解决方法 整洁的问题!只是为了澄
IntelliJ有一个很酷的功能来生成 Java getter.例如,对于一个字段private final String foo,它将生成一个getter getFoo().

有没有办法配置IntelliJ以String foo()格式生成getter?我正在主要使用不可变对象,并喜欢这种语法.

解决方法

整洁的问题!只是为了澄清@Danny Dan自从IntelliJ 15发布以来的答案…

要设置:

> Alt插入
>选择Getter
>从RHS上的“…”中打开模板配置
>从LHS创建新模板 – 请参见下面的示例
确定并选择您的新模板

示例模板:流利的吸气剂

public ##
 #if($field.modifierStatic)
   static ##
 #end
 $field.type ##
 ${field.name}() {
   return $field.name;
 }

你为什么想做这个?

结帐Implementing Domain-Driven Design:

The simple but effective approach to object design keeps the Value Object faithful to the Ubiquitous Language. The use of getValuePercentage() is a technical computer statement,but valuePercentage() is a fluent human-readable language expression.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读