UseLambdaForFunctionalInterface
should not convert when code uses a static field from enum constructor
#413
Labels
Problem
When running the
UseLambdaForFunctionalInterface
recipe, the code did no longer compile for a enum class. This enum class was a little special, as in the constructor an anonymous class was used with a reference to astatic
field. After conversion to a lambda, compilation error started to appear.What is the smallest, simplest way to reproduce the problem?
What did you expect to see?
No code change (so anonymous class should not be converted).
What did you see instead?
A conversion:
which leads to compile error:
Accessing static field from enum constructor is not allowed
.Extra info
The reason this error message appears:
static
fields in anonymous classes in the constructor are valid, but the same is not true for lambdas. This is because the loading order of enums is different from that of classes:The text was updated successfully, but these errors were encountered: