title: Scala, can't implement generic java method
body: <p>I'd like to implement a java method that uses generics in scala (2.9.2). But I'm failing...</p>
  
  <p>Java interface method:</p>
  
  <pre><code>public &lt;T extends Number&gt; void setAttribute(Key&lt;T&gt; key, Number value);
  </code></pre>
  
  <p>Scala code that want to implement that method:</p>
  
  <pre><code>def setAttribute[T &lt;: Number](key: Key[T], value: Number) = {
    setAttributeLocal(key, value)  }
  
  private def setAttributeLocal[T](key: Key[T], value: T) = {
    val stringValue = ConvertUtils.convert(value, classOf[String]).asInstanceOf[String]
    session = session + (key.getValue() -&gt; stringValue)
  }
  </code></pre>
  
  <p>Key looks like:</p>
  
  <pre><code>public class Key&lt;T&gt;
  </code></pre>
  
  <p>But this doesn't compile.</p>
  
  <pre><code>[error]  found   : mypackage.Key[T]
  [error]  required: mypackage.Key[java.lang.Number]
  [error] Note: T &lt;: java.lang.Number, but Java-defined class Key is invariant in type T.
  [error] You may wish to investigate a wildcard type such as `_ &lt;: java.lang.Number`. (SLS 3.2.10)
  [error]     setAttributeLocal(key, value)
  </code></pre>
  
  <p>I can't figure out what's the problem. Any suggestions/idea?</p>
  
  <p>greez
  GarfieldKlon</p>