I've got a class from a library (specifically, com.twitter.finagle.mdns.MDNSResolver
). I'd like to extend the class (I want it to return a Future[Set], rather than a Try[Group]).
I know, of course, that I could sub-class it and add my method there. However, I'm trying to learn Scala as I go, and this seems like an opportunity to try something new.
The reason I think this might be possible is the behavior of JavaConverters
. The following code:
class Test {
var lst:Buffer[Nothing] = (new java.util.ArrayList()).asScala
}
does not compile, because there is no asScala
method on Java's ArrayList
. But if I import some new definitions:
class Test {
import collection.JavaConverters._
var lst:Buffer[Nothing] = (new java.util.ArrayList()).asScala
}
then suddenly there is an asScala
method. So that looks like the ArrayList
class is being extended transparently.
Am I understanding the behavior of JavaConverters
correctly? Can I (and should I) duplicate that methodology?
AnyVal
to make it a value class - docs.scala-lang.org/overviews/core/value-classes.html – Mythicize