I have a trait and an implementation looking like:
trait Foo[A] {
def bar[B >: A: Ordering]: Foo[B]
}
class FooImpl[A]( val a: A, val values: List[Foo[A]] ) extends Foo[A] {
def bar[B >: A] = { /* concrete implementation */}
}
I would like to use the @specialized annotation on A and B to avoid autoboxing. Do I need to use it in both trait and implementation, only in implementation, or only in trait ?
The REPL has the right answer for us, together with javap, which will show the disassembled java code. If you add tools.jar to your REPL classpath, you will be able to do cool things like the following:
So now it should be clear to you that providing the @specialized only at trait level is enough: in the Foo interface you clearly have two method declaration. It looks to me that a trick is going on there, however:
While I can answer your question, there are some questions which I can’t answer: