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
基础教程推荐
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- JPA惰性列表上的流 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
