title: Package-relative identifier path in Java
body: <h2>Introduction</h2>
  <p>Moving from C++, one of the big differences was the difference in scoping: In C++ every identifier is relative to the current scope (<code>class</code> or <code>namespace</code>) and you could write an absolute path with the scope resolution operator <code>::</code> in the beginning.</p>
  <p>However, in Java I could not find a way to access to an identifier from other package without importing it to the current scope or writing its full path.</p>
  <p>It could be a problem if I have a few classes with the same name (then, in C++ I would address them as Module1::Foo and Module2::Foo, which is not possible in Java as long as I want to save my sanity since <code>com.company.project.module1.Foo</code> is too long for my taste).</p>
  <h2>Code!</h2>
  <p>Here's an example for accessing the class <code>Tools.Useless.Foo</code> from Java and C++ (with no <code>import</code> or <code>using</code>)</p>
  <p><code>Tools/Useless/Foo.hpp</code>:</p>
  <pre><code>namespace Tools {
  namespace Useless {
  class Foo {         
  };
  }
  }
  </code></pre>
  <p><code>Tools/Bar.hpp</code></p>
  <pre><code>namespace Tools {
  ...
  // Use Foo with a relative identifier
  Useless::Foo foo;
  // Use Foo with an absolute identifier.
  ::Tools::Useless::Foo bar;
  ...
  } 
  </code></pre>
  <p>And that's how it would look in Java:</p>
  <p><code>com/company/project/Tools/Useless/Foo.java</code>:</p>
  <pre><code>package com.company.project.Tools.Useless;
  
  public class Foo { }
  </code></pre>
  <p><code>com/company/project/Tools/Bar.java</code>:</p>
  <pre><code>...
  // Use Foo with a relative identifier
  ???
  // Use Foo with an absolute identifier.
  com.company.project.Tools.Useless.Foo foo;
  ...
  </code></pre>
  <h2>The question(s)</h2>
  <ol>
  <li>Is there a way to access <code>Foo</code> from package <code>Tools.Useless</code> without specifying <code>Tools.Useless</code> full package name (and importing it; since importing it will bind it to the current scope)?</li>
  <li>Am I doing it right? How should I use a few classes with the same name? Should I just avoid that or just import them with &quot;package.*&quot; to bypass it?</li>
  </ol>
  <h2>Solutions</h2>
  <ol>
  <li>Using more package-descriptive class names (e.g. <code>ToolsUselessFoo</code> instead of just <code>Foo</code>).</li>
  <li>Importing everything with <code>import path.to.module.*</code> instead of <code>import path.to.module.Foo</code> and then access <code>Foo</code> the the needed packages to resolve any ambiguity. The problem is that sometimes the package names has a meaning (e.g. <code>Tools.Useless.Foo</code> and <code>Tools.Useful.Foo</code>).</li>
  </ol>