摘要: class User(val userName: String,val age: Int) extends Comparable[User] { override def compareTo(o: User): Int = this.age - o.age } object OrderingDemo extends App { /** * 类型界定,上界 *... 阅读全文
posted @ 2017-09-17 09:24 bf378 阅读(279) 评论(0) 推荐(0) 编辑
摘要: @Test def testOK() = { case class Student[T, S <% Comparable[S]](var name: T, var height: S) val s = Student("john", "170") //下面这条语句在视图界定中是合法的 //因为Int类型此时会隐工转换为 //RichInt类... 阅读全文
posted @ 2017-09-17 09:23 bf378 阅读(526) 评论(0) 推荐(0) 编辑
摘要: 上下文界定的类型参数形式为T:M的形式,其中M是一个泛型,这种形式要求存在一个M[T]类型的隐式值: 阅读全文
posted @ 2017-09-17 09:20 bf378 阅读(1523) 评论(0) 推荐(0) 编辑