在Java中实现Scala PartialFunction的最简单方法是什么?

在Java中实现Scala PartialFunction的最简单方法是什么?

问题描述:

为了实现互操作性,我需要从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库,它有一个专门用于此类的类: http://twitter.github.com/util/util-core/target/site/doc/main/api/com/twitter/ util / Function.html 与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.