LoginSignup
26
26

More than 5 years have passed since last update.

Android で lombokを使う際に少しだけ楽になる方法

Posted at

lombok.config という便利なものを最近知りました

なのでまあ「lombok.config」に lombok.anyConstructor.suppressConstructorProperties = true って書いとけっつー話しです

Androidでこいつはコンパイル通らない

@Value
public class Sample {
  private String hoge;
  private String fuga;
}

よくこんなコード書くと思いますが、Androidではコンパイル通りません

@Value
^
symbol:   class ConstructorProperties
location: package java.beans
          /home/daneko/Dropbox/projects/android/sample/app/src/main/java/com/example/sample/Sample.java:7: error: cannot find symbol
@Value
^
symbol:   class ConstructorProperties
location: package java.beans
          1 error
          :app:compileDebugJava FAILED

エラーの通りjava.beans.ConstructorPropertiesが無いからです。残念。

こうするとコンパイル通る

@Value
@AllArgsConstructor(suppressConstructorProperties = true)
public class Sample {
    private String hoge;
    private String fuga;
}

こことかに記載されているとおりですね

とは言うものの… ConstructorProperties 使うもの全てにいちいちこのアノテーション書くのだるいですね

そんなどこまでも怠惰な僕らのために、lombok神は1.14から(だよね)このようなものを用意してくれていました

結論

project rootに
lombok.anyConstructor.suppressConstructorProperties = true

って書いた lombok.configつーファイル置いとけば suppressConstructorProperties = true って書かなくて済む

注意

なお intellij idea の lombok plugin は lombok.configに対応していません
どうやら作業自体は進んでいるっぽいので正座して待ちましょう

まー、 lombok.anyConstructor.suppressConstructorProperties だけなら対応しててもしてなくても関係ないですけど

26
26
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
26
26