Changed semantics by adding @Singular

52 views
Skip to first unread message

Pat

unread,
Feb 17, 2022, 6:15:44 PM2/17/22
to Project Lombok
I know the builder functionality coming with @Singular is there for quite some time, it's documented as it is, and there's most probably no way that will ever be changed... but just out of curiosity, am I the only one stumbling over issues due to changed semantics by adding @Singular to a property of any collection type?

Example:
with 

@Builder
@Data
class A {
  private List<B> bs;
}

A.builder().bs(list1).bs(list2).build();

results in an instance of A having list2.size() elements in the property bs.
If somebody adds @Singular to the property bs, the code is still valid but the semantics change: now the unchanged code results in an instance of A having list1.size()+list2.size() elements!

Even specifying a add method name via @Singular("addB") won't help as the generated method taking a collection of B's won't change.
Reply all
Reply to author
Forward
0 new messages