小编bla*_*rag的帖子

Class#getInterfaces() 和 Class#getGenericInterfaces() 返回不同长度的数组

如果您从 Scala 2.10.2 获取该类scala.runtime.AbstractPartialFunction(我没有检查其他版本)并比较 的输出AbstractPartialFunction.class.getInterfaces()AbstractPartialFunction.class.getGenericInterfaces()您可能会注意到,结果不匹配。通用接口是scala.Function1<T1, R>scala.PartialFunction<T1, R>,而 getInterfaces() 仅返回scala.PartialFunction。从scala文档中我可以看到通用信息是正确的,因为PartialFunction是一个Function1。

getInterfaces 的 javadoc 说:

如果此对象表示一个类,则返回值是一个数组,其中包含表示该类实现的所有接口的对象。数组中接口对象的顺序与该对象所表示的类的声明的implements 子句中接口名称的顺序相对应。

和 getGenericInterfaces 具有完全相同的文本。

由此(以及其他文本,包括 stackoverflow 信息)我得出结论,数组的顺序和长度是相等的。只是这里的情况并非如此。为什么?

到目前为止,我能够用几个 java7 和 java8 重现这个问题,没有尝试 java6 甚至 java5。

编辑:

AbstractPartialFunction 的 javap 输出(当然只有标头)是:

Compiled from "AbstractPartialFunction.scala"
public abstract class scala.runtime.AbstractPartialFunction<T1, R> implements scala.Function1<T1, R>, scala.PartialFunction<T1, R>`
Run Code Online (Sandbox Code Playgroud)

使用 asm lib 和 Textifier 在那里我可以看到这个头信息:

// class version 50.0 (50)
// access flags 0x421
// signature <T1:Ljava/lang/Object;R:Ljava/lang/Object;>Ljava/lang/Object;Lscala/Function1<TT1;TR;>;Lscala/PartialFunction<TT1;TR;>;
// declaration: scala/runtime/AbstractPartialFunction<T1, …
Run Code Online (Sandbox Code Playgroud)

java scala

5
推荐指数
1
解决办法
979
查看次数

Drools 6从String加载并执行规则

我试图从Drools 6中的String加载规则,如下所示:

// the rule
def drl = '''
dialect "mvel"

rule "Person is over 18"
    when
        $person : Person(age > 18)
    then
        System.out.println("Person is "+$person.name);
end
'''
// setup for rule
KieServices kieServices = KieServices.Factory.get()
KieFileSystem kfs = kieServices.newKieFileSystem()
kfs.write( "src/main/resources/simple.drl",
    kieServices.getResources().newReaderResource( new StringReader(drl) ) )
KieBuilder kieBuilder = kieServices.newKieBuilder( kfs ).buildAll()

// check there have been no errors for rule setup
Results results = kieBuilder.getResults();
if( results.hasMessages( Message.Level.ERROR ) ){
    println( results.getMessages() )
    throw new IllegalStateException( "### errors …
Run Code Online (Sandbox Code Playgroud)

drools

2
推荐指数
1
解决办法
2843
查看次数

标签 统计

drools ×1

java ×1

scala ×1