I'd like to have type-safe "subclasses" of primitives in my Scala code without the performance penalty of boxing (for a very low-latency application). For example, something like this:
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
There was a thread on the Scala User mailing list last year which seemed to conclude it wasn't possible without boxing, but I wonder if this is possible now in Scala 2.8.