value-class

Implicit conversion between Scala.Long and Java.lang.Long in collections

╄→尐↘猪︶ㄣ 提交于 2019-12-01 03:28:12
问题 I'm using JavaConverters to go from a Java SortedSet to a Vector. val lines = function.getInstructions.asScala.toVector My getInstructions function returns an ArrayList of java.lang.Long, yet the consuming code requires Scala.Long. Is there a way to do this without changing all of my consuming code to use Java.lang.Long? Furthermore, is there a way to do an implicit conversion to a value class to allow random access to the ArrayList without allocating an extra object as above? Thanks a ton

validations in value classes

拈花ヽ惹草 提交于 2019-12-01 00:53:01
SIP-15 implies one can use value classes to define for example new numeric classes, such as positive numbers. Is it possible to code such a constraint that the underlying > 0 in absence of constructor without having to call a separate method for validating the constraint (ie; creating a valid instance of such class is succint)? If value classes had the notion of constructor, then that could a place to have such validations such as below, but that is not supported (ie; code below will not compile) implicit class Volatility(val underlying: Double) extends AnyVal { require(!underlying.isNaN &&

validations in value classes

前提是你 提交于 2019-11-30 19:14:27
问题 SIP-15 implies one can use value classes to define for example new numeric classes, such as positive numbers. Is it possible to code such a constraint that the underlying > 0 in absence of constructor without having to call a separate method for validating the constraint (ie; creating a valid instance of such class is succint)? If value classes had the notion of constructor, then that could a place to have such validations such as below, but that is not supported (ie; code below will not