4

I have a problem with the following code:

public class A {
    public String someMethod() {
        return "some";
    }
}

public class AExtension {
    public static void extensionMethod(A a, String s) {
        System.out.println(a.someMethod() + s);
    }
}

@ExtensionMethod({ AExtension.class })
public class ExtensionMethodExample {

    public void test(List<String> someList) {
        A a = new A();
        someList.stream().forEach(x -> a.extensionMethod(x)); 
    }
}

And while compiling this code using Maven I get:

[ERROR] [...]ExtensionMethodExample.java:[12,49] cannot find symbol
    symbol:   method extensionMethod(java.lang.String)
    location: variable a of type [...].A

The error only occurs while compiling using Maven, while running in Eclipse everything seems to work properly.

Some of my config:

maven-compiler-plugin: 3.5.1
lombok: 1.16.10 (I also tried 1.16.2)

Update: Invocation without Lambda expression works, of course.

5kylight
  • 41
  • 3
  • should a.extensionMethod(x) call compile at all if the signature is extensionMethod(A a, String s)? – hammerfest Oct 11 '16 at 13:43
  • 2
    This is a lombok feature https://projectlombok.org/features/experimental/ExtensionMethod.html. – IgorekPotworek Oct 11 '16 at 13:49
  • Take a look at this thread, it may answer your question: http://stackoverflow.com/questions/34358689/maven-build-cannot-find-symbol-when-accessing-project-lombok-annotated-methods – Elad Tabak Nov 09 '16 at 07:51

0 Answers0