S
Stewart
Dear All,
I was hoping that the beanshell (2.0b4) would allow you to set array
elements just like any other object, by using the set command:
interpreter.set( "array[0]", object );
but it doesn't work.
You have 2 other options for dynamically setting array elements in
beanshell:
import bsh.*;
import java.io.*;
import java.util.*;
public class Test5
{
public static void main(String[] args)
throws Exception
{
Interpreter interpreter = new Interpreter(new
InputStreamReader(System.in), System.out, System.err, false);
Object array = new Long[3];
interpreter.set( "array", array );
// option 1 - doesn't work
interpreter.set( "array[0]", new Long(1) );
interpreter.eval( "print( array )" );
// option 2
interpreter.set( "temp", new Long(2) );
interpreter.eval( "array[1] = temp" );
interpreter.eval( "print( array )" );
// option 3
java.lang.reflect.Array.set( array, 2, new Long(3));
interpreter.eval( "print( array )" );
}
}
Stewart,
London, UK
I was hoping that the beanshell (2.0b4) would allow you to set array
elements just like any other object, by using the set command:
interpreter.set( "array[0]", object );
but it doesn't work.
You have 2 other options for dynamically setting array elements in
beanshell:
import bsh.*;
import java.io.*;
import java.util.*;
public class Test5
{
public static void main(String[] args)
throws Exception
{
Interpreter interpreter = new Interpreter(new
InputStreamReader(System.in), System.out, System.err, false);
Object array = new Long[3];
interpreter.set( "array", array );
// option 1 - doesn't work
interpreter.set( "array[0]", new Long(1) );
interpreter.eval( "print( array )" );
// option 2
interpreter.set( "temp", new Long(2) );
interpreter.eval( "array[1] = temp" );
interpreter.eval( "print( array )" );
// option 3
java.lang.reflect.Array.set( array, 2, new Long(3));
interpreter.eval( "print( array )" );
}
}
Stewart,
London, UK