[Py4j-users] How do I cast Java objects between types on the Python side?
Status: Beta
Brought to you by:
barthe
From: Chris A. <chr...@gm...> - 2013-09-07 04:16:25
|
Hi all. I'm trying to implement this code in Python: (from http://www.hypergraphdb.org/learn?page=IntroStoreData&project=hypergraphdbat the bottom, modified so I don't have to implement a class on the Java side) bookHandle = graph.add("asdf") priceHandle = graph.add(9.95) link = new gateway.jvm.org.hypergraphdb.HGValueLink("price", bookHandle, priceHandle) The problem is that in the Python code, the call to graph.add() from the Python side is yielding an object of type WeakHandle that implements HGLiveHandle, and HGValueLink only accepts HGHandle[] in its arguments. The end result is that the java side throws an exception saying that a HGValueLink constructor doesn't exist that takes [String, handle.WeakHandle, handle.WeakHandle]. (Relevant javadocs at http://www.kobrix.com/javadocs/hgcore/org/hypergraphdb/HGValueLink.html, http://www.kobrix.com/javadocs/hgcore/org/hypergraphdb/HyperGraph.html, http://www.kobrix.com/javadocs/hgcore/org/hypergraphdb/handle/HGLiveHandle.html ) In the linked example the two handles are declared as HGHandle when they're instantiated, so there's no problem when the method call does typechecking. It seems to me, then, that the easiest way to rectify this is to use some facility of the Gateway to re-cast the object returned from graph.add() as HGHandle, and then just pass that the the HGValueLink constructor as it wants. Can I do that from the gateway as it exists, or do I have to add a method to my server code to cast it? Am I missing an easier and more obvious solution in my Java inexperience? Thanks, Chris |