scala.collection.script.Message 上的 scala 模式匹配
我正在尝试在地图上创建订阅者。
这是代码:
type Msg = Message[(SomeObject)] with undoable
class mySub extends Subscriber[Msg,HashMap] {
def notify(pub:HashMap, evt: Msg) = {
evt match{
case Include(NoLo,x) => println(x)
}
}
}
在上面的通知中,如果我只是打印 evt,我会得到输出:- Include(NoLo, someobject)..但是如果我尝试 case Include 代码将无法编译说找到: Include required: Message
Is Include not a subclass of信息?如何测试不同的消息,例如包含、删除等。
I am trying to create a subscriber on a map.
here is the code:
type Msg = Message[(SomeObject)] with undoable
class mySub extends Subscriber[Msg,HashMap] {
def notify(pub:HashMap, evt: Msg) = {
evt match{
case Include(NoLo,x) => println(x)
}
}
}
in the notify above if i just print evt I get output:- Include(NoLo, someobject)..but if I try case Include the code wont compile saying found: Include required: Message
Is Include not a subclass of Message? How do you test for different messages like include, remove etc..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以编译这个:
有趣的是,当
Undoable
混合在一起时,模式匹配将无法编译......I can get this to compile:
Funny enough, the pattern matching won't compile when
Undoable
is mixed in…更详细一点,但这是我想到的:
正如您所注意到的,您必须引用 Message 子类上的 elem val 才能获取键或值。
A little more verbose but here is what I came up with:
As you note you have to reference the elem val on subclasses of Message to get the key or the value.