Tuesday, October 12, 2010

Function syntax for native java objects

I'm making some good progress on integrating java objects.
I now have function syntax working for object variables.

Here's an interesting example of mixing functions, jset, and the function syntax

# Define a function jnew which creates a String
$ jnew () {
local _x ;
jset -v _x -c java.lang.String "$@"
return $_x;
}

# Create a string object
$ a=jnew("hi there")

# Check its value
$ echo $a
hi there


# Check its type
$ xtype $a
java.lang.String


# Call the length method
$ echo a.length()
8

# Call the concat method
$ echo a.concat(" some more")
hi there some more


No comments:

Post a Comment

Due to comment spam, moderation is turned on. I will approve all non-spam comments.