Scala视图界定

 

 

  @Test
  def testOK() = {
    case class Student[T, S <% Comparable[S]](var name: T, var height: S)
    val s = Student("john", "170")
    //下面这条语句在视图界定中是合法的
    //因为Int类型此时会隐工转换为
    //RichInt类,而RichInt类属于Comparable、
    //继承层次结构
    val s2 = Student(190, 170)

  }

 

posted @ 2017-09-17 09:23  bf378  阅读(526)  评论(0编辑  收藏  举报