I've been fiddling with the Java support lately, and it appears that while the Java bridge has no real documentation, it's pretty full featured. That said, I'm trying to get a feel for the limitations, and ran into one that just doesn't seem right:
if I create a new java array of any type other than string, I can't assign values to it:
example using string:
import Java; object t=machine->find_class("java/lang/String"); object o=pkg["java/lang/reflect/Array"]->newInstance(t, 5); o[0]="foo"; o[1]="bar";
works just fine, but this example using integers doesnt:
import Java; object t=machine->find_class("java/lang/Integer"); object o=pkg["java/lang/reflect/Array"]->newInstance(t, 5); o[0]=12; o[1]=5;
incompatible types passed to method. jvm.c:3550: jvm.c:3550()->`[]=(0,1) /usr/local/pike/7.4.20/lib/modules/Java.pmod:301: Java.jarray()->`[]=(0,1) test.pike:7: test()->main()
Any ideas? I had been using java the manual way by manually connecting methods, and it worked fine using Array.set() (admittedly a different technique).
Thanks!
Bill
I've been fiddling with the Java support lately, and it appears that while the Java bridge has no real documentation, it's pretty full featured. That said, I'm trying to get a feel for the limitations, and ran into one that just doesn't seem right:
if I create a new java array of any type other than string, I can't assign values to it:
example using string:
import Java; object t=machine->find_class("java/lang/String"); object o=pkg["java/lang/reflect/Array"]->newInstance(t, 5); o[0]="foo"; o[1]="bar";
works just fine, but this example using integers doesnt:
import Java; object t=machine->find_class("java/lang/Integer"); object o=pkg["java/lang/reflect/Array"]->newInstance(t, 5); o[0]=12; o[1]=5;
incompatible types passed to method. jvm.c:3550: jvm.c:3550()->`[]=(0,1) /usr/local/pike/7.4.20/lib/modules/Java.pmod:301: Java.jarray()->`[]=(0,1) test.pike:7: test()->main()
Any ideas? I had been using java the manual way by manually connecting methods, and it worked fine using Array.set() (admittedly a different technique).
I have no idea if this is correct or not, but it's not an issue with int vs Integer and pike not converting a Pike int to Java Integer automatically? Can you create an Integer object and assign that?
/ David Hedbor
Previous text:
2003-09-04 20:13: Subject: arrays in Java
I've been fiddling with the Java support lately, and it appears that while the Java bridge has no real documentation, it's pretty full featured. That said, I'm trying to get a feel for the limitations, and ran into one that just doesn't seem right:
if I create a new java array of any type other than string, I can't assign values to it:
example using string:
import Java; object t=machine->find_class("java/lang/String"); object o=pkg["java/lang/reflect/Array"]->newInstance(t, 5); o[0]="foo"; o[1]="bar";
works just fine, but this example using integers doesnt:
import Java; object t=machine->find_class("java/lang/Integer"); object o=pkg["java/lang/reflect/Array"]->newInstance(t, 5); o[0]=12; o[1]=5;
incompatible types passed to method. jvm.c:3550: jvm.c:3550()->`[]=(0,1) /usr/local/pike/7.4.20/lib/modules/Java.pmod:301: Java.jarray()->`[]=(0,1) test.pike:7: test()->main()
Any ideas? I had been using java the manual way by manually connecting methods, and it worked fine using Array.set() (admittedly a different technique).
Thanks!
Bill
/ Brevbäraren
You're absolutely right, I just forgot that I was passing a jobject rather than the "unwrapped" object to the assignment. I'm going to update the java module to handle that case, as I'm sure I'm not the only one who'll forget that. :)
It does seem to be slightly inconsistent that you can pass a straight string, but not any of the other "primitive" types.
Bill
I have no idea if this is correct or not, but it's not an issue with int vs Integer and pike not converting a Pike int to Java Integer automatically? Can you create an Integer object and assign that?
/ David Hedbor
Well it is quite consistent to java. You specified Integer which is an object. In java you can't do 'Integer foo = 10' either but rather 'Integer foo = new Integer(10)'.
/ David Hedbor
Previous text:
2003-09-04 22:21: Subject: Re: arrays in Java
You're absolutely right, I just forgot that I was passing a jobject rather than the "unwrapped" object to the assignment. I'm going to update the java module to handle that case, as I'm sure I'm not the only one who'll forget that. :)
It does seem to be slightly inconsistent that you can pass a straight string, but not any of the other "primitive" types.
Bill
I have no idea if this is correct or not, but it's not an issue with int vs Integer and pike not converting a Pike int to Java Integer automatically? Can you create an Integer object and assign that?
/ David Hedbor
/ Brevbäraren
But just because Java is less than comfy to program in doesn't mean that the Pike interface for Java must be too.
/ Martin Nilsson (ja till euro, nej till cent)
Previous text:
2003-09-04 22:50: Subject: Re: arrays in Java
Well it is quite consistent to java. You specified Integer which is an object. In java you can't do 'Integer foo = 10' either but rather 'Integer foo = new Integer(10)'.
/ David Hedbor
Sure, it could be fixed but then you wouldn't be consistent with java. Now, converting from int to Integer is probably ok but the opposite is not. Also how would you solve the problem with:
JavaInteger = BIGNUMBER;
fail? Wrap?
/ David Hedbor
Previous text:
2003-09-04 22:57: Subject: Re: arrays in Java
But just because Java is less than comfy to program in doesn't mean that the Pike interface for Java must be too.
/ Martin Nilsson (ja till euro, nej till cent)
I've written "wrappers" for some of the basic pike (and then some) datatypes:
Integer, Boolean, String, Float, Array, HashMap
The array helper can do array(array|mapping) and the hashmap helper can do mapping(int|float|string|mapping|array|object : int|float|string|mapping|array|object) :)
They're very basic, and not completely consistent with how pike objects of similar datatype would work, but it's much easier to link up with java when you don't have to reinvent the wheel.
Might this be useful in the Java module?
Also, I was wondering what the closest java equivalent to a multiset would be. Any thoughts?
Bill
On Thu, 4 Sep 2003, Martin Nilsson (ja till euro, nej till cent) @ Pike (-) developers forum wrote:
But just because Java is less than comfy to program in doesn't mean that the Pike interface for Java must be too.
/ Martin Nilsson (ja till euro, nej till cent)
Previous text:
2003-09-04 22:50: Subject: Re: arrays in Java
Well it is quite consistent to java. You specified Integer which is an object. In java you can't do 'Integer foo = 10' either but rather 'Integer foo = new Integer(10)'.
/ David Hedbor
Also, I was wondering what the closest java equivalent to a multiset would be. Any thoughts?
Some data type that handles an ordered index that can contain duplicate entries.
/ Martin Stjernholm, Roxen IS
Previous text:
2003-09-04 23:39: Subject: Re: arrays in Java
I've written "wrappers" for some of the basic pike (and then some) datatypes:
Integer, Boolean, String, Float, Array, HashMap
The array helper can do array(array|mapping) and the hashmap helper can do mapping(int|float|string|mapping|array|object : int|float|string|mapping|array|object) :)
They're very basic, and not completely consistent with how pike objects of similar datatype would work, but it's much easier to link up with java when you don't have to reinvent the wheel.
Might this be useful in the Java module?
Also, I was wondering what the closest java equivalent to a multiset would be. Any thoughts?
Bill
On Thu, 4 Sep 2003, Martin Nilsson (ja till euro, nej till cent) @ Pike (-) developers forum wrote:
But just because Java is less than comfy to program in doesn't mean that the Pike interface for Java must be too.
/ Martin Nilsson (ja till euro, nej till cent)
Previous text:
2003-09-04 22:50: Subject: Re: arrays in Java
Well it is quite consistent to java. You specified Integer which is an object. In java you can't do 'Integer foo = 10' either but rather 'Integer foo = new Integer(10)'.
/ David Hedbor
/ Brevbäraren
Right, I figured as much, I was just surprised when the other datatypes weren't working.
Bill
On Thu, 4 Sep 2003, David Hedbor @ Pike developers forum wrote:
Well it is quite consistent to java. You specified Integer which is an object. In java you can't do 'Integer foo = 10' either but rather 'Integer foo = new Integer(10)'.
/ David Hedbor
Previous text:
2003-09-04 22:21: Subject: Re: arrays in Java
You're absolutely right, I just forgot that I was passing a jobject rather than the "unwrapped" object to the assignment. I'm going to update the java module to handle that case, as I'm sure I'm not the only one who'll forget that. :)
It does seem to be slightly inconsistent that you can pass a straight string, but not any of the other "primitive" types.
Bill
I have no idea if this is correct or not, but it's not an issue with int vs Integer and pike not converting a Pike int to Java Integer automatically? Can you create an Integer object and assign that?
/ David Hedbor
/ Brevb�raren
No, pike doesn't have the same problem (or doesn't have to have it) since pike has operator overloading. Just add the appropriate operators and your object should in many ways interact well with native datatypes.
/ David Hedbor
Previous text:
2003-09-04 23:34: Subject: Re: arrays in Java
In java you can't do 'Integer foo = 10'
you can in pike? ok, pike does not have an Integer class, but if one would exist it would have the same problem, wouldn't it?
same with the other types.
greetings, martin.
/ Brevbäraren
true, except in the example you mentioned because = can't be overloaded.
greetings, martin.
If we are really picky, it's possible, though not from the Pike level. int foo = 10000000000000000000; does create a Gmp.mpz object... :-)
/ Johan Sundström (utan sälskap)
Previous text:
2003-09-04 23:34: Subject: Re: arrays in Java
In java you can't do 'Integer foo = 10'
you can in pike? ok, pike does not have an Integer class, but if one would exist it would have the same problem, wouldn't it?
same with the other types.
greetings, martin.
/ Brevbäraren
I thought so too, but,
| > int foo = 10000000000000000000; | > objectp(foo); | (1) Result: 0
Appearantly not. :-)
/ Mirar
Previous text:
2003-09-05 10:25: Subject: Re: arrays in Java
If we are really picky, it's possible, though not from the Pike level. int foo = 10000000000000000000; does create a Gmp.mpz object... :-)
/ Johan Sundström (utan sälskap)
It disguises itself well.
int foo = 10000000000000000000; foo->sqrt();
(1) Result: 3162277660
foo->probably_prime_p();
(2) Result: 0
/ Johan Sundström (utan sälskap)
Previous text:
2003-09-05 10:26: Subject: Re: arrays in Java
I thought so too, but,
| > int foo = 10000000000000000000; | > objectp(foo); | (1) Result: 0
Appearantly not. :-)
/ Mirar
That's doesn't mean anything. ;)
| > 17->sqrt(); | (2) Result: 4 | > 17->probably_prime_p(); | (3) Result: 2
/ Mirar
Previous text:
2003-09-05 10:32: Subject: Re: arrays in Java
It disguises itself well.
int foo = 10000000000000000000; foo->sqrt();
(1) Result: 3162277660
foo->probably_prime_p();
(2) Result: 0
/ Johan Sundström (utan sälskap)
gmtime(10000000000000000000);
Bad argument 1 to gmtime(). Expected int
/ Martin Nilsson (ja till euro, nej till cent)
Previous text:
2003-09-05 10:34: Subject: Re: arrays in Java
That's doesn't mean anything. ;)
| > 17->sqrt(); | (2) Result: 4 | > 17->probably_prime_p(); | (3) Result: 2
/ Mirar
([ /* 10 elements */ "hour":17, "isdst":0, "mday":11, "min":46, "mon":2, "sec":40, "timezone":0, "wday":0, "yday":42, "year":316887387038 ])
(Okay, I cheated. :-)
/ Johan Sundström (utan sälskap)
Previous text:
2003-09-05 11:07: Subject: Re: arrays in Java
gmtime(10000000000000000000);
Bad argument 1 to gmtime(). Expected int
/ Martin Nilsson (ja till euro, nej till cent)
| > gmtime(100000000000000); | (2) Result: ([ /* 10 elements */ | "hour":14, | "isdst":0, | "mday":5, | "min":53, | "mon":9, | "sec":52, | "timezone":0, | "wday":4, | "yday":277, | "year":78 | ])
Hmmm.
/ Mirar
Previous text:
2003-09-05 11:07: Subject: Re: arrays in Java
gmtime(10000000000000000000);
Bad argument 1 to gmtime(). Expected int
/ Martin Nilsson (ja till euro, nej till cent)
A k a gmtime(100000000000000&0x1FFFFFFF). Still interesting.
/ Johan Sundström (utan sälskap)
Previous text:
2003-09-05 11:28: Subject: Re: arrays in Java
| > gmtime(100000000000000); | (2) Result: ([ /* 10 elements */ | "hour":14, | "isdst":0, | "mday":5, | "min":53, | "mon":9, | "sec":52, | "timezone":0, | "wday":4, | "yday":277, | "year":78 | ])
Hmmm.
/ Mirar
I stubbornly run my Pikes with 64 bit ints and floats, so I'm quite used to see these effects usually while being to do anything about it.
I wouldn't mind a few other people running their Pike the same way. :) (--with-long-long-int --with-double-precision.)
/ Mirar
Previous text:
2003-09-05 11:33: Subject: Re: arrays in Java
A k a gmtime(100000000000000&0x1FFFFFFF). Still interesting.
/ Johan Sundström (utan sälskap)
pike-devel@lists.lysator.liu.se