eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Unreported "illegal reference to static field from initializer" in relation to javac
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 49
Description
Copied and updated from https://bugs.eclipse.org/bugs/show_bug.cgi?id=577373:
Originally I mentioned this in https://bugs.eclipse.org/bugs/show_bug.cgi?id=533475#c3, but it seems to be a different error since that bug was fixed and this one remains.
The code
```java
enum MyEnum {
;
private static MyEnum selected;
private MyEnum() {
Supplier s = () -> selected = this;
}
}
```
compiles fine in Eclipse, but using Gradle I get the error:
```
C:\ZSwitch\src\main\java\switchTests\SwitchTest.java:39: error: illegal reference to static field from initializer
Supplier s = () -> selected = this;
^
```
I don't know which compiler is correct, but unless the specifications are lenient, these should be aligned.
I first encountered it with Java 10 and Eclipse 4.7.3, and it's the same with Java 21 and Eclipse 4.29.
Contributor guide
Assessment
This issue has not been assessed yet.