Scala - understand class definition with Bounds

I am learning Scala, and I have seen some classes built using the template:

how

class Name[+S <: State](val name: String)


class User[S <: State] {
  def state(implicit n: Name[S]): String = n.name
}

What does here <:and mean +S?

And does the sate function do?

thank

+4
source share
1 answer

Here are a few keywords that might be helpful:

For <:and >:, check the borders of the upper and lower types: https://twitter.imtqy.com/scala_school/type-basics.html#bounds

For S+both S-covariant and contravariant types: https://twitter.imtqy.com/scala_school/type-basics.html#variance

, , , : http://docs.scala-lang.org/tutorials/tour/implicit-parameters.html

+4

Source: https://habr.com/ru/post/1674901/


All Articles