问题描述
为了实现互操作性,我需要从Java代码传递Scala PartialFunction。对于Function(Function1等),我可以使用匿名类型对AbstractFunction进行子类化,但对PartialFunction执行相同操作的最简单方法是什么?
For interoperability, I need to pass a Scala PartialFunction from Java code. For Function (Function1 and so on), there is AbstractFunction that I can subclass with an anonymous type, but what would be the easiest way of doing the same for PartialFunction?
在这种情况下,我很乐意将它作为Java中的完整函数,出现为所有值定义,但键入为PartialFunction。
In this case, I would be happy to have it being a "complete" function in Java, appearing defined for all values, but typed as a PartialFunction.
推荐答案
如果您可以使用Twitter Util库,它有一个专门用于此类的类:与AbstractPartialFunction基本相同。
If you can use Twitter Util library, it has a class specifically for this: http://twitter.github.com/util/util-core/target/site/doc/main/api/com/twitter/util/Function.html which is basically the same solution as AbstractPartialFunction.
这篇关于在Java中实现Scala PartialFunction的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!