beanshell arrays

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top