Skip to main content



      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 06:33 Go to next message
Eclipse UserFriend
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 10:18 Go to previous message
Eclipse UserFriend
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: Mon Jul 14 10:08:28 EDT 2025

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

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

Back to the top