Re: [Py4j-users] How do I cast Java objects between types on the Python side?
Status: Beta
Brought to you by:
barthe
From: Barthelemy D. <bar...@in...> - 2013-09-07 10:13:16
|
Hi Chris, glad you could fix it! I was replying with exactly this solution when I saw you had sent a follow up. Barthélémy On Sat, Sep 7, 2013 at 1:53 AM, Chris Akins <chr...@gm...> wrote: > Hi, all. > Issue's resolved. I had to create the array of HGHandles that the > constructor was expecting by hand, so > Java: > x=new HGValueLink("asdf", h1, h2) > > became Python: > a=new_array(HGHandle, 2); > a[0]=h1; > a[1]=h2; > x=gateway.jvm.org.hypergraphdb.hGValueLink("asdf",a) > > Thanks for your hard work. > > -Chris > > > On Sat, Sep 7, 2013 at 12:16 AM, Chris Akins <chr...@gm...> wrote: >> >> Hi all. >> >> I'm trying to implement this code in Python: (from >> http://www.hypergraphdb.org/learn?page=IntroStoreData&project=hypergraphdb >> at 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 >> > > > ------------------------------------------------------------------------------ > Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more! > Discover the easy way to master current and previous Microsoft technologies > and advance your career. Get an incredible 1,500+ hours of step-by-step > tutorial videos with LearnDevNow. Subscribe today and save! > http://pubads.g.doubleclick.net/gampad/clk?id=58041391&iu=/4140/ostg.clktrk > _______________________________________________ > Py4j-users mailing list > Py4...@li... > https://lists.sourceforge.net/lists/listinfo/py4j-users > |