IntelliJ IDEA将final添加到自动生成的setter中 [英] IntelliJ IDEA add final to auto-generated setters

查看:1634
本文介绍了IntelliJ IDEA将final添加到自动生成的setter中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将最终关键字添加到IntelliJ IDEA 14中自动生成的setter中的参数。我知道我可以创建用于setter方法的当前模板的副本:

I am trying to add the final keyword to the parameters in my auto-generated setters in IntelliJ IDEA 14. I know that I can create a copy of the current template which is used for setter methods:

#set($paramName = $helper.getParamName($field, $project))
public ##
#if($field.modifierStatic)
  static ##
#end
void set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))($field.type $paramName) {
  #if ($field.name == $paramName)
    #if (!$field.modifierStatic)
      this.##
    #else
      $classname.##
    #end
  #end
  $field.name = $paramName;
}

但即使在玩了几个小时后,我也无法解决如何添加final并使其在IntelliJ中工作。

But even after playing around with it for hours, I can't work out how to add "final" to it and get it to work in IntelliJ.

推荐答案

你不需要这样做模板。

转到设置(Windows: Ctrl + Alt + S ) / Preferences(Mac: Command +

Go to Settings (Windows: Ctrl+Alt+S) / Preferences (Mac: Command+,)


  • 编辑|代码风格| Java

  • 选择代码生成选项卡

  • 勾选生成参数最终

  • Editor | Code Style | Java
  • Select the Code Generation tab
  • Tick Make generated parameters final

这篇关于IntelliJ IDEA将final添加到自动生成的setter中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆