Are there any shortcut type restrictions in Scala?

When defining a covariant class, all method declarations must contain something line by line:

[B >: A] //A is the main type variable

      

Is there a way to declare something at the class level that makes B available so I don't have to repeat this in every method?

I've tried everything I can think of using type

, but nothing compiled.

+3


source to share


1 answer


It turns out that this is possible.

class Test[+A] {
    type B >: A
    def doStuff(b : B): B = ...
} 

      



I thought it would be there =

.

Note. I have not tested it completely. It seems to work the same, but I don't know for sure.

+1


source







All Articles