Scala 类型重定义: 将 Int 转换为 spx_int32
/**
* SPX32 Int 类型
*/
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/on1L 著作权归作者所有。请勿转载和采集!