title: Calling java generic function from scala
body: <p>I am new to scala and am having an issue in calling a "generic" function in the java NIO library (from scala 2.10.x).  Reducing the code to a simple test:</p>
  
  <pre><code>import java.net._
  import java.nio.channels.{MembershipKey, DatagramChannel}
  
  object Test {
    val channel = DatagramChannel.open(StandardProtocolFamily.INET)
      .setOption(StandardSocketOptions.SO_REUSEADDR, true)
      ...
  }
  </code></pre>
  
  <p>This results in: </p>
  
  <pre><code>Error:(40, 48) type mismatch;
   found   : java.net.SocketOption[Boolean]
   required: java.net.SocketOption[Any]
  Note: Boolean &lt;: Any, but Java-defined trait SocketOption is invariant in type T.
  You may wish to investigate a wildcard type such as `_ &lt;: Any`. (SLS 3.2.10)
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, true)
                                             ^
  </code></pre>
  
  <p>I assume there is some way to resolve this without resorting to writing a wrapper in java.  Have tried recasting in a variety of ways without success.</p>
  
  <p>Question: how do I resolve the above?</p>