1
我有一个函数,它接受输入两个BitSet,然后我在Groovy中调用评估。 由于参数是两个BitSet,所以我需要将它们初始化为内联并通过一个字符串传递所有内容。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同一块代码(S3 VAR)是不行的,因为它返回以下错误:
Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: No expression for the array constructor call at line: 1 column: 29. File: Script1.groovy @ line 1, column 29.
path(BitSet.valueOf(new long[] {0b00111111}),BitSet.valueOf(new long[] {0b00000011}))
^
谷歌搜索我发现,Groovy中接受阵列与以下格式inizialitation:
- [0b00111111]只要[]
- 长[] O = [0b00111111]
正如你可以通过代码看到的,我试图在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()
S2的错误是:
Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 1: Invalid use of declaration inside method call.
有没有办法解决这个问题的方法吗?