Scala: Pattern matching with generic case classes -
Scala: Pattern matching with generic case classes -
is possible match generic case classes? thought utilize generic case classes messages between actors.
thats approach: there anyway create possible?
case class ebtreedataobject[t](uid: long, changeid: long, payload:option[t]) case class insertnewobject[t](newobject: ebtreedataobject[t]) case class updateobject[t](changedobject: ebtreedataobject[t]) class treeactor[t](maxsynchrowait:int,communication:communikationlayer[t]) extends actor { var uidtree = new ebtree[ebtreedataobject[t]] var changeidtree = new ebtree[ebtreedataobject[t]] override def receive: receive = { //basic tree operations case insertnewobject(newobject: ebtreedataobject[t]) => //insert element in tree case updateobject(newobject: ebtreedataobject[t]) => //update object case removeobject(removedobject: ebtreedataobject[t]) => //remove object
this constructs give error while compiling:
error:(32, 37) pattern type incompatible expected type; found : model.ebtreedataobject[t] required: model.ebtreedataobject[any] note: t <: any, class ebtreedataobject invariant in type t. may wish define t +t instead. (sls 4.5) case insertnewobject(newobject: ebtreedataobject[t]) =>
thanks help
why don't compiler suggests:
case class ebtreedataobject[+t](uid: long, changeid: long, payload: option[t])
scala generics pattern-matching
Comments
Post a Comment