我想在我的Scala代码中使用基本类型安全的"子类",而不会出现拳击的性能损失(对于非常低延迟的应用程序).例如,像这样:
class Timestamp extends Long
class ProductId extends Long
def process(timestamp: Timestamp, productId: ProductId) {
...
}
val timestamp = 1: Timestamp // should not box
val productId = 1: ProductId // should not box
process(timestamp, productId) // should compile
process(productId, timestamp) // should NOT compile
Run Code Online (Sandbox Code Playgroud)
去年Scala用户邮件列表上有一个帖子似乎得出结论,没有拳击是不可能的,但我想知道现在Scala 2.8是否可行.