I created Value Class
final class Feature(val value: Vector[Double]) extends AnyVal
In matchagainst this class in scala:
val d = new Feature(Vector(1.1))
s match {
case a:Feature => println(s"a:feature, $a")
case _ => println("_")
}
This works correctly, but in Akka, with the same class above, in the method receivethis does not work:
def receive = LoggingReceive {
case a:Feature =>
log.info("Got Feature: {}", a)
case _ => println("_")
}
When I execute the code, although I submit Feature, the statement casethat is executed case _ => println("_"), but, if I change the code to this:
def receive = LoggingReceive {
case a:Feature =>
log.info("Got Feature: {}", a)
case b:Vector[_] =>
log.info("GOT FEATURE")
case _ => println("_")
}
case b:Vector[_].
Akka documentation mentions:
The recommended way to create instances of actor details uses reflection at runtime to determine the correct construction of the actor, called and due to technical limitations, when the specified constructor accepts arguments that are value classes. In these cases, you must either unpack the arguments or create the props by calling the constructor manually:
Value classes
Update
. Actor :
, :
def receive = LoggingReceive {
case Feature(a) =>
log.info("Got feature {}", a)
}
:
def receive = LoggingReceive {
case json: JValue =>
log.info("Getting json response, computing features...")
val features = Feature(FeatureExtractor.getFeatures(json))
log.debug(s"Features: $features")
featureListener.get ! features
}