1
0

More than 3 years have passed since last update.

【IntelliJ IDEA】Javaファイル保存時にfinalを自動的につける方法

Posted at

やりたいこと

  • Javaのコードを書くときに、immutableにしたい変数には、finalを付けておきたい
  • ただ毎回finalを書くのは大変なので、ファイル保存時に自動的にfinalを付けるようにしたい

環境

  • IntelliJ IDEA 2020.2.2
  • Mac OS Catalina 10.15.7

やり方

Save Actions プラグインを利用するので、「IntelliJ IDEA」 -> 「Preferences」 -> 「Plugins」 を押下して、Save Actionsをインストール
スクリーンショット 2020-09-27 0.19.02.png

「IntelliJ IDEA」 -> 「Preferences」 -> 「Other Settings」 -> 「Save Actions」を押下して、
以下の項目にチェックを入れ、「Apply」, 「OK」を押下

  • Activate save actions on save (...)
  • Add final modifier to field
  • Add final modifier to local variable or parameter
    • (もしくは Add final modifier to local variable or parameter except if it is implicit)

スクリーンショット 2020-09-27 0.20.34.png

これで、「Cmd+s」を実行するとfinalが自動的に付与されるようになります。
sample1.gif

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0