64

Scala 语言学习之泛型(7)-骑猪去旅行-51CTO博客

 6 years ago
source link: http://blog.51cto.com/songqinglong/2072568
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

share_default.jpg

骑猪去旅行 > Scala > 正文

Scala 语言学习之泛型(7)

==> 泛型类

        ---> T 可以代表任意类型

class Person[T]{  private var name:T = _  def setName(name:T) = {this.name = name}  def getName():T = {this.name}}// ***********测试*****************object Person{  def main(args:Array[String]):Unit = {    var p = new Person[String]()    p.setName("hello")    println(p.getName())  }}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK