LoginSignup
1
0

LombokのBuilderとValueを同時につけたらall args constructorはパッケージプライベートになる

Last updated at Posted at 2024-03-21

タイトルの通り。

@Value付与したら@AllArgsConstructorも付いてくるのだが、@Builderも同時に付与すると、そちらで生成するパッケージプラベートなコンストラクターで上書きされてしまうらしい。

Note that if both `@Builder` and `@Value` are on a class, 
the package private allargs constructor that `@Builder` 
wants to make 'wins' over the public one that `@Value` wants to make. 

どちらも付与した上でpublicなall args constructorが欲しい場合は、明示的にAllArgsConstructorをつけてやれば良い。

下記だとall args constructorはパッケージプライベートになる。

@Value
@Builder
public class Dto {

下記はall args constructorはパブリックになる。

@Value
@Builder
@AllArgsConstructor
public class OnlinePageImageDto {
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