首页 > 其他 > 详细

Type parameter

时间:2016-04-15 07:04:53      阅读:219      评论:0      收藏:0      [点我收藏+]

Type will be erased by compiler.

Compiler warning message:

Warning:(21, 13) non-variable type argument Int in type pattern A[Int] is unchecked since it is eliminated by erasure
    case a: A[Int] => println("Int" + a.getClass)
            ^
Warning:(22, 13) non-variable type argument scala.util.Try[Int] in type pattern A[scala.util.Try[Int]] is unchecked since it is eliminated by erasure
    case a: A[Try[Int]] => println("TryInt" + a.getClass)
            ^

 

Output:

Intclass AInt
Intclass ATryInt

 

Code:

import scala.util.Try

trait A[T] {

}

class AInt extends A[Int] {

}

class ATryInt extends A[Try[Int]]

object Test extends App {
  val a = new AInt()
  val aTryInt = new ATryInt()

  p(a)
  p(aTryInt)

  def p[T](a: A[T]) = a match {
    case a: A[Int] => println("Int" + a.getClass)
    case a: A[Try[Int]] => println("TryInt" + a.getClass)
  }
}

 

Type parameter

原文:http://www.cnblogs.com/neweracoding/p/5393867.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!