Access to the Java Global Namespace

Given the following program:

class A {
   static int java = 42;
   static int System = -1;

   public static void main(String[] args) {
      java.lang.System.out.println("Foo");
   }
}

Compiling this gives me an error saying that "int cannot be dereferenced." The reason is obvious, but how to handle such situations. This is especially true in code generation scenarios where it is impossible to know which user code is interwoven with the generated code.

In C #, I would just use the namespace specifier "global ::" to "java.lang", but what do you do in Java?

+5
source share
1 answer

There is no general solution in Java. We live with it

  • abide by naming conventions that distinguish class names from package / field names and
  • qualify static var with its class name when generating code.
+3

All Articles