Frage

I have a java class "JavaClass" with a method:

boolean addAll(java.util.Collection<? extends java.lang.Integer> collection) { ... }

I need to create a Scala trait MyTrait that includes this method without an implementation, something like

def addAll[A<:java.lang.Integer](coll: java.util.Collection[A]) : Boolean

so that an implementation

class MyClass extends JavaClass with MyTrait

would not be abstract. But I can't figure out any way to match the Java signature in Trait.

FWIW... I'm trying to write some high-performance Scala-collection-compatible wrappers for Trove, which avoids generics to provide high performance with primitives, but used highly consistent interfaces for each primitive type. I've found that in general, traits work well to model the type-independent demi-interfaces, but I can't figure out how to express this particular signature - even ignoring, for the moment, the type-abstraction I'm using the trait for.

War es hilfreich?

Lösung

Collection<? extends java.lang.Integer> in java is equivalent to

Collection[T] forSome {type T <: java.lang.Integer}

or using placeholder syntax Collection[_ <: java.lang.Integer] in scala

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top