title: Nested Scala singletons from Java code
body: <p>I have the following Scala (2.8) code:</p>
  
  <pre><code>object A {
    val message = "hello"
    object B {
      val message = "world"
    }
  }
  </code></pre>
  
  <p>And a similar Java class:</p>
  
  <pre><code>public class C {
    public static String message() {
      return "HELLO";
    }
    public static class D {
      public static String message() {
        return "WORLD";
      }
    }
  }
  </code></pre>
  
  <p>These work as I'd expect when I call them from Scala:</p>
  
  <pre><code>scala&gt; A.message  
  res0: java.lang.String = hello
  
  scala&gt; A.B.message
  res1: java.lang.String = world
  
  scala&gt; C.message  
  res2: java.lang.String = HELLO
  
  scala&gt; C.D.message
  res3: java.lang.String = WORLD
  </code></pre>
  
  <p>But when I try something similar from Java, the compiler doesn't like the second line:</p>
  
  <pre><code>System.out.println(A.message());
  System.out.println(A.B.message()); // cannot find ... symbol  : variable B ...
  System.out.println(C.message());
  System.out.println(C.D.message());
  </code></pre>
  
  <p>It's clear why this is the case when I look at the class files with <code>javap</code>. I know I can use</p>
  
  <pre><code>System.out.println(A$B$.MODULE$.message());
  </code></pre>
  
  <p>instead, or add something like <code>val getB = B</code> to my <code>A</code> object and replace the second line with</p>
  
  <pre><code>System.out.println(A.getB().message());
  </code></pre>
  
  <p>Is there a standard way to use nested Scala singleton objects from Java code?</p>