projectlombok / lombok

Very spicy additions to the Java programming language.
https://projectlombok.org/
Other
12.9k stars 2.39k forks source link

[BUG] @Delegate does not work properly on enums #3057

Open nlisker opened 2 years ago

nlisker commented 2 years ago

enum ASD { }

class FADSF {

    @Delegate
    ASD asd;
}

In Eclipse, the annotation generates the enum methods 3 times: image

If you exclude the Enum methods, you are left with the Comparable one, but also 3 times:

@Delegate(excludes = java.lang.Enum.class)
ASD asd;

image

Also, excluding java.lang.Comparable.class does not remove the compareTo method. I think that that it is because it's a generic interface and @Delegate has known limitations with generics. Then again, Enum is also a generic type and its methods are removed.

Adding a custom method to the enum also causes that one to be generated 3 times, so it's not just those declared in Enum.

Using Eclipse 4.21 and Lombok 1.18.22.


I'm trying to find a way to delegate only my custom methods from an enum (and only once), Excluding Enum helps, but the compareTo method is still there and all methods appear 3 times.

Rawi01 commented 2 years ago

I guess that only the outline is wrong. The support for adding the generated delegate methods in the outline is quite new so most likely it simply doesn't work properly.

nlisker commented 2 years ago

Alright, if it's just the IDE then it's not too bad. What about excluding the Comparable method?

DidierLoiseau commented 5 months ago

It does not seem to be only an IDE issue, the following compiles and prints hello, so the compareTo() delegate is definitely generated despite the excludes:

enum ASD {
  TEST;

  public static void main(String[] args) {
    if (new FADSF().compareTo(ASD.TEST) == 0) {
      System.out.println("hello");
    }
  }
}

class FADSF {

  @Delegate(excludes = {Enum.class, Comparable.class})
  ASD asd = ASD.TEST;
}