Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Missing code implementation in the compiler(Confusing differences in compiler behavior between eclipse and javac)
Missing code implementation in the compiler [message #1868088] Thu, 11 July 2024 10:33 Go to next message
Sten Willey is currently offline Sten WilleyFriend
Messages: 1
Registered: July 2024
Junior Member
Hello. This error is not critical, but this difference in behavior confused me. The problem is in the code that creates an anonymous class, inside of which there is a static method that accesses a local variable. javac does not compile such code at all, while eclipse compiles the code successfully if assignment is constant.
I.e. if testLocal = foo() javac gives 'error: non-static variable testLocal cannot be referenced from a static context' and eclipse gives 'missing code implementation in the compiler'.
If testLocal = 1 javac gives the same error but eclipse compiles code successfully and code can be executed.

public class Main {
    private static int foo() {
        return 1;
    }

    public static void main(String[] args) {
        final int testLocal = 1;
        Object obj = new Object() {
            public static void foo() {
                System.out.println(testLocal);
            }
        };
        try {
            obj.getClass().getMethod("foo").invoke(null);
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
Re: Missing code implementation in the compiler [message #1868112 is a reply to message #1868088] Thu, 11 July 2024 14:18 Go to previous message
Erik BrangsFriend
Messages: 55
Registered: February 2010
Member
This sounds like a possible bug. I advise you to report it directly via GitHub, see https://github.com/eclipse-jdt .
Previous Topic:Problem With Play Background Music in Android Application
Next Topic:Junit5 + Mockito testcases are not working in Eclipse
Goto Forum:
  


Current Time: Sun Jan 26 13:16:17 GMT 2025

Powered by FUDForum. Page generated in 0.02824 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top