beanshell arrays

Discussion in 'Java' started by Stewart, Sep 12, 2006.

  1. Stewart

    Stewart Guest

    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
     
    Stewart, Sep 12, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SOl

    [BEANSHELL] Extends

    SOl, Jul 19, 2003, in forum: Java
    Replies:
    0
    Views:
    395
  2. Wolfgang Groiss
    Replies:
    0
    Views:
    402
    Wolfgang Groiss
    Nov 19, 2003
  3. Michael Pitoniak
    Replies:
    1
    Views:
    559
    Michael Pitoniak
    Dec 20, 2003
  4. vnssoftware
    Replies:
    0
    Views:
    446
    vnssoftware
    Feb 4, 2004
  5. Robert
    Replies:
    0
    Views:
    363
    Robert
    Jul 6, 2004
Loading...

Share This Page