0610.泛型(Generics)

內容

    沒有標題

    Generics

    Scala 自動型別推斷


    scala> (1: Integer)::"H"::Nil          
    warning: there were deprecation warnings; re-run with -deprecation for details
    res4: List[java.lang.Comparable[_ >: java.lang.String with java.lang.Integer <: java.lang.Comparable[_ >: java.lang.String with java.lang.Integer <: java.io.Serializable] with java.io.Serializable] with java.io.Serializable] = List(1, H)

    scala> 1 :: "s1" :: "s2" :: Nil
    res5: List[Any] = List(1, s1, s2)

    scala> val l: List[AnyRef] = (1: Integer) :: "s1" :: "s2" :: Nil
    warning: there were deprecation warnings; re-run with -deprecation for details
    l: List[AnyRef] = List(1, s1, s2)


    scala> val l: List[AnyRef] = (99: Integer) :: (98: Integer) :: "s1" :: "s2" :: (9: Integer) :: Nil
    warning: there were deprecation warnings; re-run with -deprecation for details
    l: List[AnyRef] = List(99, 98, s1, s2, 9)

    scala> System.out.printf("%d%n", l: _*)
    99

    res3: java.io.PrintStream = java.io.PrintStream@16ff6348






    [T <: String]


    Comments