且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Drools右侧创建新的Scala对象

更新时间:2023-11-30 12:51:34

从Scala对象类型导入方法在Drools中可能会出现问题。原因很简单,与Java相比,Scala中不存在 static 方法。这是因为Scala对成为纯面向对象的语言的含义进行了更严格的解释。

Importing methods from Scala Object types can be problematic in Drools. The simple reason is that static methods do not exist in Scala in contrast with Java. This is because Scala takes a more stricter interpretation of what it means to be a pure object orientated language.

这意味着,无论何时您尝试使用Drools import函数语法,它找不到要导入的任何静态方法。结果,Drools编译器抱怨对Scala单例对象类型中包含的方法的任何引用。

What this means is that whenever you try to use the Drools import function syntax, it cannot find any static methods to import. As a result, the Drools compiler complains about any references to methods contained in Scala singleton object types.

为此的一种解决方法是编写将要编写的所有类。在Java的DRL中使用,可以在其中显式定义静态方法。 Scala编译器将很高兴将它们与您的Scala类一起编译。

A work around for this is to write any classes which are going to be used in your DRLs in Java where you can explicitly define static methods. The Scala compiler will happily compile these along with your Scala classes.