Reputation: 1771
I was tring to use getDatasID
from Factory.java
in test.scala
.
//Factory.java
class Factory {
...
public <K, V, T extends Datas<K, V>> DatasID<T> getDatasID(Class <T> dataClass) ...
}
// C.java
public class C extends Datas<Key, Value> { ... }
I used two class in scala to run getDatasID
//Test.scala
abstract class A[K, V, T[K, V] <: Datas[K, V]]
abstract class B extends Datas[Key, Value]
val targetA = new Factory()
.getDatasID(
classOf[A
[Key, Value, ({type T[K, V]=Datas[Key, Value})#T]
])
val targetB = new Factory()
.getDatasID(classOf[B])
Both class showed same error.
[Nothing, Nothing A[Key, Value, [K, V]Datas[Key, Value]]]
do not conform ... [K,V,T <: Datas[K,V]]
type mismatch
class[A[Key, Value, [K,V]Datas[Key, Value]]](classOf[A])
Class[T]
I would like to match class[Key, Value, Datas[Key, Value]]. The best case will be
val targetB = new Factory()
.getDatasID(classOf[B])
Above code works.
Upvotes: 1
Views: 159
Reputation: 170735
Scala can't infer K
and V
in this situation, you need to supply them explicitly:
new Factory.getDatasId[Key, Value, B](classOf[B])
or
new Factory.getDatasId[Key, Value, A[Key, Value, _ <: Datas[Key, Value]](classOf[A])
(depending on which class you need to pass). If possible, it would be better to change your Java signature, since it doesn't actually use K
and V
:
public <T extends Datas<?, ?>> DatasID<T> getDatasID(Class <T> dataClass)
Upvotes: 4