Defined the following implicit def meant to implement some methods required by an Akka actor event bus. The methods required are outlined in the documentation here: http://doc.akka.io/docs/akka/2.0/scala/event-bus.html#Subchannel_Classification
protected implicit def subclassification: Subclassification[Classifier] = {
def isEqual(a: Classifier, b: Classifier): Boolean = {
a.equals(b)
}
def isSubclass(a: Classifier, b: Classifier): Boolean = {
a.startsWith(b)
}
}
However, when I go to compile it I get the error: type mismatch; found : Unit required: akka.util.Subclassification[MessageBus.this.Classifier]
Here’s what the documentation asks for specifically:
subclassification: Subclassification[Classifier]is an object
providing isEqual(a: Classifier, b: Classifier) and isSubclass(a:
Classifier, b: Classifier) to be consumed by the other methods of this
classifier.
I’m aware that this would return a unit, but how would I make the implementations necessary that could also provide those member methods?
Did you mean to instantiate a subclass of
Subclassification[Classifier]? If so, you need to saynew Subclassification[Classifier]so that Scala knows that what’s you’re trying to do.The reason it complains is because you are assigning to the variable
subclassificationa block of code that contains only two function declarations. Since Scala always assumes the last expression in the block to be what the expression evaluates to, and the type of a function declaration isUnit(basically meaning that it doesn’t evaluate to anything), Scala says that the entire block has typeUnit.Since you are assigning the block to the variable
subclassification,subclassificationmust be of typeUnit. But you explicitly state that the type should beSubclassification[Classifier], so there is a mismatch, and you get an error.