Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
beanshell arrays
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Stewart, post: 1932778"] 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 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
beanshell arrays
Top