Skip to main content

Posts

Showing posts with the label pass-by-reference

Java Variable References when using Lists

Just a thought question here. In C++, I could do the following: vector<vector<string> > data; // add data into data //.. data[0].push_back( "somedata" ); And I would expect somedata to get written to the vector array because the [] notation gives me access to the object by reference. What about in Java? If I: List<List<String>> data = new ArrayList<List<String>>(); // add data into data //.. data.get(0).add( "somedata" ); Would this actually write somedata into the data object? Or would it create a new copy of the element at data(0), add somedata to that, and then that object disappears into GC sometime down the line?

JNI how get values updated to int and double fields

How do two values I pass into my JNI tossed down to C then C does its changes and updates the values. How do I get those two values(maxPower, index) and see then in Java? They always come back as zero. JNIEXPORT jdouble JNICALL Java_com_TV ( JNIEnv* env, jobject obj, jdouble maxPower, jint index) { jdouble result = 0; result = Feature_TV(2, &maxPower, &index ); return result; } // here is the c function it calls it actually does more than this but for // demo it should return result 60 and maxPower and index should be -5.0 and -2.. double Feature_TV(double * maxPwr, int * maxPwrIdx ) { *maxPwr = -5.0; *maxPwrIdx = -2; /// do something return 60; }