setting arrays

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

setting arrays

Stewart Cambridge
Dear Beanshell Users,

I was expecting the following to work, but apparently it doesn't:

Object array = new Object[3];
interpreter.set( "myArray", array );
interpreter.set( "myArray[0]", someObject );

I have to do it this way:

Object array = new Object[3];
interpreter.set( "myArray", array );
interpreter.set( "temp", someObject );
interpreter.eval( "myArray[0] = temp" );

Anyone care to comment?

Stewart,
London, UK

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: setting arrays

Stewart Cambridge
This simple test shows the options:

import bsh.*;
import java.io.*;
import java.util.*;

public class Test
{
  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
    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 )" );
  }
}

On 12/09/06, Stewart Cambridge <[hidden email]> wrote:

> Dear Beanshell Users,
>
> I was expecting the following to work, but apparently it doesn't:
>
> Object array = new Object[3];
> interpreter.set( "myArray", array );
> interpreter.set( "myArray[0]", someObject );
>
> I have to do it this way:
>
> Object array = new Object[3];
> interpreter.set( "myArray", array );
> interpreter.set( "temp", someObject );
> interpreter.eval( "myArray[0] = temp" );
>
> Anyone care to comment?
>
> Stewart,
> London, UK
>

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: setting arrays

Jan de Visser
In reply to this post by Stewart Cambridge
On Tuesday 12 September 2006 06:36, Stewart Cambridge wrote:

> Dear Beanshell Users,
>
> I was expecting the following to work, but apparently it doesn't:
>
> Object array = new Object[3];
> interpreter.set( "myArray", array );
> interpreter.set( "myArray[0]", someObject );
>
> I have to do it this way:
>
> Object array = new Object[3];
> interpreter.set( "myArray", array );
> interpreter.set( "temp", someObject );
> interpreter.eval( "myArray[0] = temp" );
>
> Anyone care to comment?

Object array = new Object[3];
array[0] = someObject;
interpreter.set( "myArray", array );

jan


--
--------------------------------------------------------------
Jan de Visser                     [hidden email]

                Baruk Khazad! Khazad ai-menu!
--------------------------------------------------------------

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users