用scala描述一个int类型重新定义成spx_int32类型
/**
* SPX32 Int type
*/
class spx_int32(val value: Int) extends AnyVal {
override def toString: String = value.toString
}
object spx_int32 {
def apply(value: Int): spx_int32 = new spx_int32(value)
def unapply(arg: spx_int32): Option[Int] = Some(arg.value)
}
使用方法:
val i: spx_int32 = spx_int32(10)
println(i) // 输出 10
原文地址: https://www.cveoy.top/t/topic/fIoZ 著作权归作者所有。请勿转载和采集!