Java global namespace access

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 should one handle situations like this. It is especially relevant in code-generation scenarios, where one cannot know what user code is intertwined with generated code.

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

Answers


No general solution in Java. The way we live with this is to

  1. respect naming conventions, which distinguish class names from package/field names, and
  2. qualify static var with its class name when generating code.

Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.