我在JVM中创建了一个hashmap,想在jpype.shutdownJVM之后访问它,我该怎么做?
我知道dict在python中用作hashmap,我试过:
jpype.startJVM(jpype.getDefaultJVMPath(),“ - Djava.class.path =%s”%classpath) hashmap = jpype.java.util.HashMap() ...#插入对 jpype.shutdownJVM() ... hashmap [“key”]这不起作用。
感谢。
答案 0 :(得分:0)
密钥访问将映射到java调用。由于你关闭了jvm,这将无法工作。
您必须首先从Java HashMap创建一个新的python目录。确保这些值不是复杂的Java对象,并且可以获得translated automatically。
import jpype
jpype.startJVM(jpype.getDefaultJVMPath())
hashmap = jpype.java.util.HashMap()
# insert pairs
hashmap.put("foo", "bar")
# normally newmap = dict(hashmap) should work but jpype
# doesn't seem to support this...
newmap = {}
for i in hashmap:
# you might have to map more complex keys or values to python objects
# before putting them into newmap
newmap[i] = hashmap[i]
jpype.shutdownJVM()
print newmap["foo"]