Using Peer class with JNI problem, how to return the java object reference?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Wei_Cui
Posted On:   Thursday, May 15, 2003 09:50 PM

Here is about the Peer Class: http://developer.java.sun.com/developer/JDCTechTips/2001/tt0612.html What if i want to return a object reference? Say there is java class "anotherPeer", it also has a long type objptr to hold the pointer to C++ class "AnotherPeerClass". In C++ class "PeerClass", there is a new member of "AnotherPeerClass" type: Class PeerClass { int val; AnotherPeerClass another; ..... } While there is method "getAnotherPeer" in the java "Peer" class, public anotherPeer getAnotherPeer() { long anotherPtr = getanotherp   More>>

Here is about the Peer Class:
http://developer.java.sun.com/developer/JDCTechTips/2001/tt0612.html


What if i want to return a object reference?
Say there is java class "anotherPeer", it also has a long type objptr to hold the pointer to C++
class "AnotherPeerClass".

In C++ class "PeerClass", there is a new member of "AnotherPeerClass" type:


Class PeerClass {

int val;

AnotherPeerClass another;

.....

}




While there is method "getAnotherPeer" in the java "Peer" class,

public anotherPeer getAnotherPeer() {

long anotherPtr = getanotherpeer(objptr); //the
//implementation may call native function like getanotherpeer(objptr) to get the pointer of the AnotherPeerClass object.

........ // but how to return the anotherPeer object reference holding?

};



Now i can only compose a new AnotherPeer object and then let its objptr equals to the tmpPtr. But it is not the same reference with the one created before
like this,


Peer p = new Peer();

AnotherPeer ap = new AnotherPeer();

p.setAnotherPeer(ap);

AnotherPeer tmp = p.getAnotherPeer();// tmp is different

reference with ap, but they hold the same objptr



I really want the tmp reference is the same with ap. Anyone knows well abt this? Thanks.

   <<Less
About | Sitemap | Contact