码迷,mamicode.com
首页 > 其他好文 > 详细

Type parameter

时间:2016-04-15 07:05:30      阅读:107      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!