2017年2月17日星期五

scala object apply default type parameter with more constructor

/**  * Created by eagooqi on 2017/2/17.  */class UTest[T] () {
  var _id:String = _
  def this(id:String){
    this()
    this._id = id
  }
}
object UTest{

  def apply[T](id:String) = new UTest[T](id)
  def apply[Nothing](id:String) = new UTest[String](id)

}

object Test2 extends App{
  var ut: UTest[String] = UTest[String]("")
  var ut2  = UTest("")
  println(ut2.getClass.getTypeName)
}

没有评论:

发表评论