Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Groovy数组初始化_Java_Groovy - Fatal编程技术网

Java Groovy数组初始化

Java Groovy数组初始化,java,groovy,Java,Groovy,我有一个函数,它接受两个位集的输入,然后,我通过在Groovy中求值来调用这个函数。 由于参数是两个位集,我需要内联初始化它们,并通过字符串传递所有内容 public static void main(String[] args) { Binding binding = new Binding(); GroovyShell shell = new GroovyShell(binding); path(BitSet.valueOf(new long[] {0b0011111

我有一个函数,它接受两个位集的输入,然后,我通过在Groovy中求值来调用这个函数。 由于参数是两个位集,我需要内联初始化它们,并通过字符串传递所有内容

public static void main(String[] args) {
    Binding binding = new Binding();
    GroovyShell shell = new GroovyShell(binding);
    path(BitSet.valueOf(new long[] {0b00111111}),BitSet.valueOf(new long[] {0b00000011})); //s3
    //String s1 = "path(BitSet.valueOf([0b00111111L] as long[]),BitSet.valueOf([0b00111111L] as long[]))";
    //String s2 = "path(BitSet.valueOf( long[] o = [0b00111111L] ),BitSet.valueOf( long[] oo = [0b00111111L] ))";
    String s3 = "path(BitSet.valueOf(new long[] {0b00111111}),BitSet.valueOf(new long[] {0b00000011}))";
    Object value = shell.evaluate(s3);


}

public static LinkedList<BitSet> path(BitSet dstBitSet, BitSet srcBitSet) {
    LinkedList<BitSet> l = new LinkedList<>();
    l.add(srcBitSet);
    System.out.println("ok");
    return l;
}
通过谷歌搜索,我发现Groovy接受以下格式的数组序列化:

  • [0B0011111]尽可能长[]
  • 长[]o=[0B0011111]
正如您从代码中看到的,我尝试在var s1和s2中执行相同的操作,但仍然不起作用。 S1错误为:

Exception in thread "main" groovy.lang.MissingMethodException: No   signature of method: Script1.path() is applicable for argument types:   (java.util.BitSet, java.util.BitSet) values: [{0, 1, 2, 3, 4, 5}, {0, 1,   2, 3, 4, 5}]
Possible solutions: wait(), any(), with(groovy.lang.Closure), each(groovy.lang.Closure), run(), run()
Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: Invalid use of declaration inside method call.
S2错误为:

Exception in thread "main" groovy.lang.MissingMethodException: No   signature of method: Script1.path() is applicable for argument types:   (java.util.BitSet, java.util.BitSet) values: [{0, 1, 2, 3, 4, 5}, {0, 1,   2, 3, 4, 5}]
Possible solutions: wait(), any(), with(groovy.lang.Closure), each(groovy.lang.Closure), run(), run()
Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: Invalid use of declaration inside method call.
有办法解决这个问题吗?

试试这个:

path(BitSet.valueOf([0b00111111] as long[]), BitSet.valueOf([0b00111111] as long[]))
试试这个:

path(BitSet.valueOf([0b00111111] as long[]), BitSet.valueOf([0b00111111] as long[]))