有没有一种方法可以给密封特征起别名,以提供类型安全?我知道我可以编写一个案例类或求助于类型类,但是这些解决方案我想做的太过分了。
一个简单的例子来说明它:
type Lon = Double
type Lat = Double
def lonLatPair(lon:Lon, lat:Lat):(Lon, Lat) = (lon, lat)
val someLon:Lon = 1.2
val someLat:Lat = 3.4
lonLatPair(someLon, someLat) // Success!
lonLatPair(someLat, someLon) // Dismal failure in the form of a type error