title: Java-Scala interop issue involving BoxedUnit/void return types
body: <p>I have the same problem as in <a href="https://stackoverflow.com/questions/26643045">Java interoperability woes with Scala generics and boxing</a>, but I don't think the solution there will work for me because it would require a modification to third-party code.</p>
  
  <p>Specifically, <em>from Java</em> (say MyJavaClass) I'm trying to extend a Scala class (MyScalaClass) that itself extends <a href="https://twitter.github.io/util/docs/index.html#com.twitter.app.App" rel="nofollow noreferrer">com.twitter.app.App</a>. App extends <a href="https://twitter.github.io/util/docs/index.html#com.twitter.util.CloseAwaitably" rel="nofollow noreferrer">com.twitter.util.CloseAwaitably</a>, and this in turn extends <a href="https://twitter.github.io/util/docs/index.html#com.twitter.util.Awaitable" rel="nofollow noreferrer">com.twitter.util.Awaitable</a>.</p>
  
  <pre><code>Awaitable            // trait where `result` is defined
   ^-CloseAwaitably    // trait with some impl of `result`
     ^-App             // trait with no mention of `result`
       ^-MyScalaClass  // abstract class with no mention of `result`
         ^-MyJavaClass // just trying to get this guy to compile
                       // and it expects an impl of `result`
  </code></pre>
  
  <p>All that to say that when I finally get to extending MyScalaClass by writing MyJavaClass, I get</p>
  
  <blockquote>
    <p>[ERROR] MyJavaClass.java:[11,8] MyJavaClass is not abstract and does
    not override abstract method
    result(com.twitter.util.Duration,com.twitter.util.Awaitable.CanAwait)
    in com.twitter.util.Awaitable</p>
  </blockquote>
  
  <p>I figured I just have to implement <code>result</code> for some reason, so I do, in MyJavaClass:</p>
  
  <pre><code>public void result(com.twitter.util.Duration d,
                     com.twitter.util.Awaitable.CanAwait c)
  {}
  </code></pre>
  
  <p>Now I get</p>
  
  <blockquote>
    <p>[ERROR] return type void is not compatible with scala.runtime.BoxedUnit</p>
  </blockquote>
  
  <p>Changing my method to</p>
  
  <pre><code>public BoxedUnit result(com.twitter.util.Duration d,
                          com.twitter.util.Awaitable.CanAwait c)
  {return BoxedUnit.UNIT;}
  </code></pre>
  
  <p>results in</p>
  
  <blockquote>
    <p>[ERROR] return type scala.runtime.BoxedUnit is not compatible with void</p>
  </blockquote>
  
  <p>What the heck... So then I start googling. The answer to <a href="https://stackoverflow.com/questions/26643045">Java interoperability woes with Scala generics and boxing</a> seems to say that Scala generates Java-incompatible bytecode in my situation, and that I could hack around the problem if I had control of some of the Twitter classes (I <em>think</em> CloseAwaitably) to genericize  it with <code>[U &lt;: Unit]</code> and <code>return ().asInstanceOf[U]</code> in the original method implementation to trick scalac into admitting the possibility of "some not-exactly-Unit type" (though I'm not totally clear on how this works).</p>
  
  <p>I don't have control over the Twitter classes, only MyScalaClass and MyJavaClass. <em>I don't actually care about the</em> <code>result</code> <em>method</em> - I just want to be able to extend MyScalaClass from MyJavaClass, implementing some abstract methods I defined in MyScalaClass. For what it's worth, I'm using Scala 2.10.4, JDK 1.8, and (twitter) util-core_2.10 6.22.0, and in case this is relevant: I don't really know why it's requiring me to implement <code>result</code> in the first place. A Scala class inheriting from MyScalaClass doesn't have to implement that method, and builds just fine.</p>
  
  <p>How can I get around this? Thanks for playing.</p>