Re: How to invoke assignment operator in a native method?



HappyHippy <karenman@xxxxxxx> wrote:
I want to achieve the effect of the following assignment (which can be
done in Java)

SomeNumber = 5;

where SomeNumber is of type java.lang.Integer

But in a native method I do not have an Integer object, I have jobject
instead.

In addition to Gordon and Oliver's replies, let me be explicit about
something. When you write:

SomeNumber = 5;

which is equivalent to:

SomeNumber = Integer.valueOf(5);

you are not doing *anything* the object that SomeNumber currently points
to. You are reassigning SomeNumber to point to a completely new object.
You say you've got a jobject, but you don't say which one it is. The
jobject that SomeNumber points *to* doesn't help you at all.
Presumably, SomeNumber is a field (you can't access local variables of
Java methods from JNI at all), and you need the jobject that *contains*
the SomeNumber field. Once you've got that, then you can call
SetObjectField as Gordon described.

Incidentally, naming conventions are there for a reason, and are
absolutely universal among professional Java programmers. Call the
field someNumber, not SomeNumber.

--
Chris Smith
.