getLastNonConfigurationInstance always returning null(getLastNonConfigurationInstance 总是返回 null)
问题描述
HashMap myMap = (HashMap) getLastNonConfigurationInstance();
myMap 始终为空.getLastNonConfigurationInstance() 返回一个对象.我的地图有两个键符号"和名称".
myMap is always null. getLastNonConfigurationInstance() returns an object. My map has two keys "symbol" and "name".
public Object onRetainNonConfigurationInstance()
{
HashMap myMap = new HashMap();
myMap.put("symbol", this.symbol);
final Object data = myMap;
return data;
}
推荐答案
如果 getLastNonConfigurationInstance()
返回一个非空对象,那么 (HashMap) getLastNonConfigurationInstance()
将要么返回相同的对象(如果该对象是 HashMap
),或者抛出 ClassCastException
.
If getLastNonConfigurationInstance()
returns a non-null object, then (HashMap) getLastNonConfigurationInstance()
will either return the same object (if that object is a HashMap
), or throw a ClassCastException
.
您描述的情况是不可能的,除非您在 Java 的强制转换运算符中发现了一个长期隐藏的错误.提示:你没有.
The situation that you describe is not possible, not unless you've uncovered a long-hidden bug in Java's cast operator. Hint: you haven't.
验证 getLastNonConfigurationInstance()
实际上返回的是非空对象.验证 myMap
实际上是否为空.如果您使用调试器检查这些值,请尝试将它们打印到控制台.调试器有时会欺骗您,或者至少会误导您.
Verify that getLastNonConfigurationInstance()
is actually returning a non-null object. Verify that myMap
is actually null. If you're using a debugger to check those values, try printing them to the console instead. Debuggers can lie to you sometimes, or at least mislead.
这篇关于getLastNonConfigurationInstance 总是返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:getLastNonConfigurationInstance 总是返回 null


基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01