Error trying to call Java method from Rascal

放肆的年华 提交于 2019-12-11 11:09:56

问题


I am trying to call a Java method from Rascal, but I'm getting this error:

Cannot link method com.mypackage.Teste because: class not found

Rascal code:

@javaClass{com.mypackage.Teste}
java void testeJava();

Java code:

package com.mypackage;

public class Teste {
    public void testeJava() {
        System.out.println("it worked");
    }
}

The com.mypackage package is inside my src folder, along with all of the Rascal code. I've also tried to use src.com.mypackage.Teste as well, but had the same result.

What am I doing wrong?


回答1:


The class needs one constructor that has one argument of the IValueFactory type. You will often store this in a field, as it is the way to respond to the function call. (Build IValues with this factory)

package com.mypackage;

import io.usethesource.vallang.IValueFactory;

public class Teste {
    private final IValueFactory vf;

    public Tests(IValueFactor vf) {
       this.vf = vf;
    }
    public void testeJava() {
        System.out.println("it worked");
    }
}


来源:https://stackoverflow.com/questions/47855421/error-trying-to-call-java-method-from-rascal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!