0

Hello I have the following class structure -

@Getter
@SuperBuilder(toBuilder = true)
@ToString
@NoArgsConstructor
abstract class A {
   String a;
}


@Getter
@SuperBuilder(toBuilder = true)
@ToString
@AllArgsConstructor
class B extends A {
  String b;
}


public A setAField(final A aObj, final String setA) {
  return aObj.toBuilder().a(setA).build();
}

The IDE is showing error as its not able to find the toBuilder() method. Do I need to cast to concrete before calling the toBuilder()?

Jan Rieke
  • 7,027
  • 2
  • 20
  • 30
  • 3
    Lombok has a feature called "delombok", replacing the annotations with the code normally generated at compile-time. I suggest taking a look at what lombok generates. --- If you are still learning the language, I recommend to not use advanced tools like lombok; they will do more harm than good. – Turing85 Aug 14 '23 at 16:09

1 Answers1

1

toBuilder() is an instance method. To use the static method for the builder, use builder():

A.builder().a(setA).build();

Or use the aObj instance in your method:

aObj.toBuilder().a(setA).build();
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • My bad I made a mistake in the question. I am using the `aObj.toBuilder().a(setA).build()`. The ide is not able to recognise this. – Vegan Vegeta Aug 14 '23 at 16:39