Scala - 用Bounds理解类定义

时间:2017-04-15 23:05:09

标签: scala class templates operators

我正在学习Scala,并且我已经看到了一些使用模板构建的类:

像:

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


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

这里的含义是<:+S

sate功能在做什么?

由于

1 个答案:

答案 0 :(得分:4)

以下是一些可能有用的关键字:

对于View reputationColor = (View)findViewById(R.id.reputationColor); switch (reputation) { case 1: reputationColor.setBackgroundColor(#ff0000); break; //Include other cases up to 5 default: break; } <:,请查看上下类型边界:https://twitter.github.io/scala_school/type-basics.html#bounds

对于>:S+,协变和逆变类型:https://twitter.github.io/scala_school/type-basics.html#variance

要了解状态函数的作用,请查看隐式参数的工作原理:http://docs.scala-lang.org/tutorials/tour/implicit-parameters.html

相关问题