This question is about working with generic types and setting the bound, so please do not freak out because of the library I use. Treat it as an example.
I work with Scalala and use such types DenseMatrix[V]
, DenseVectorCol[V]
and DenseVectorRow[V]
. The common super type for them is Tensor[K,V]
. Note that the Tensor
has additional parameter K
-- all the mentioned classes Dense...
set this type K
by themselves.
So I would like to write a method with argument which upper type bound is Tensor
. I wrote such code for my method:
def validate[K,T <: Tensor[K,Double]](tensor : T) : T = ...
with such intention -- T
has to be subtype of Tensor
, and I know I work with Double
s all the time, so let it be Double
, and for first type argument (K
) get it from passed argument.
It does not work as I expected because I get error:
inferred type arguments [Nothing,DenseVectorCol[Double]] do not conform to method validate's type parameter bounds [K,T <: Tensor[K,Double]]
QUESTION: so how to extract this type K
from the passed argument?