mercredi 23 avril 2014

Using implicit as type constraint


Vote count:

0




As far as I know, there are 2 ways to add type constraint. trait Dummy 1. def doStuff[T < Dummy](x: T) = x 2. def doStuff[T](x: T)(implicit x: T <:< Dummy) = x


Both achieve the same result.


I just wonder that what kind of scenarios I should use the upper bound or lower bound directly, or I should use implicit to append the constraint on the type.


Thanks in advance and it would be nice for a code example.



asked 35 secs ago






Aucun commentaire:

Enregistrer un commentaire