Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 实现PyObject';Jython中的dict查找方法:(uu finditem+;?)_Java_Jython - Fatal编程技术网

Java 实现PyObject';Jython中的dict查找方法:(uu finditem+;?)

Java 实现PyObject';Jython中的dict查找方法:(uu finditem+;?),java,jython,Java,Jython,我有一个扩展了PyObject的Java类,它包含一个Map,我想我应该在Jython中免费获得dict行为。相反,我得到了一个错误TypeError:myclassname对象不可订阅 看起来我必须至少实现该方法(参见第654-670行): 我该怎么做?是否有检查PyObject是否为字符串的示例?如果键不是字符串,会发生什么 我是否也必须覆盖\uuuuuuuuuuuuuuuuuuu (这与类似,但有一个相对简单的解决方案。) /** * Very similar to the standa

我有一个扩展了
PyObject
的Java类,它包含一个
Map
,我想我应该在Jython中免费获得
dict
行为。相反,我得到了一个错误
TypeError:
myclassname
对象不可订阅

看起来我必须至少实现该方法(参见第654-670行):

我该怎么做?是否有检查
PyObject
是否为
字符串的示例?如果键不是字符串,会发生什么

我是否也必须覆盖
\uuuuuuuuuuuuuuuuuuu

(这与类似,但有一个相对简单的解决方案。)

/**
 * Very similar to the standard Python __getitem__ method.
 * Instead of throwing a KeyError if the item isn't found,
 * this just returns null.
 *
 * Classes that wish to implement __getitem__ should
 * override this method instead (with the appropriate
 * semantics.
 *
 * @param key the key to lookup in this container
 *
 * @return the value corresponding to key or null if key is not found
 **/
public PyObject __finditem__(PyObject key) {
    throw Py.TypeError(String.format("'%.200s' object is unsubscriptable",
                                     getType().fastGetName()));
}