3

I am an embedded C programmer and was integrating my code written in native C/C++ with Java using JNI. I was curios to know whether pass by reference for primitive data_type be possible? I am refering this link http://java.sun.com/docs/books/jni/html/objtypes.html#5279 which doesnt help my cause.

Basically what i want to achieve is something like this : // Get the val updated by the native call int nativeFunc(short val); Java Function :

class main
{
   short val;
   val = 0;
   nativeFunc(val);
   System.out.println(val)
}

int nativeFunc(short val)
{
   // Code to update OUt param val
   // Need this portion
}

I dont know if its very trivial question with a very easy answer.

Michael Slade
  • 13,802
  • 2
  • 39
  • 44
Jitender
  • 76
  • 6
  • It would be somuseful to have instance's variable name quering for such thing >< I lack this future so much.... – Vitali Pom Oct 06 '16 at 17:59

1 Answers1

3

Java is always pass-by-value. For a discussion, see Is Java "pass-by-reference" or "pass-by-value"?

You could either return the modified primitive from the function, or change it to take an object holding the primitive.

Community
  • 1
  • 1
NPE
  • 486,780
  • 108
  • 951
  • 1,012