消除unchecked cast Warning

简介: 消除unchecked cast Warning

将一个Object类型转成自己想要的Map、List等,会出现 unchecked cast Warning 警告。

Map<String, String> castMap = (HashMap<String, String>) obj;


解决办法,添加一个方法:

@SuppressWarnings("unchecked")
public static <T> T cast(Object obj) {
    return (T) obj;
}


使用:

Map<String, String> row = cast(JSONObject.parse(rowEntity));
相关文章
C++ 编译错误 error: ‘cout‘ was not declared in this scope (摄氏度与华氏度的转换)
C++ 编译错误 error: ‘cout‘ was not declared in this scope (摄氏度与华氏度的转换)
C++ 编译错误 error: ‘cout‘ was not declared in this scope (摄氏度与华氏度的转换)
|
存储 Java 编译器
【Java异常】Variable used in lambda expression should be final or effectively final
【Java异常】Variable used in lambda expression should be final or effectively final
271 0
【Java异常】Variable used in lambda expression should be final or effectively final
|
8月前
|
数据库
Greenplum【异常 03】COPY命令报错 > ERROR: invalid input syntax for type double precision: ““(问题分析及解决方案)数据去重
Greenplum【异常 03】COPY命令报错 > ERROR: invalid input syntax for type double precision: ““(问题分析及解决方案)数据去重
248 0
|
安全 C语言
警告 1 warning C4996: ‘scanf‘: This function or variable may be unsafe.
警告 1 warning C4996: ‘scanf‘: This function or variable may be unsafe.
|
关系型数据库 MySQL C++
类型收窄 error C2397: conversion from ‘const int‘ to ‘char‘ requires a narrowing conversion
类型收窄 error C2397: conversion from ‘const int‘ to ‘char‘ requires a narrowing conversion
213 0
|
Java 编译器
规避Variable used in lambda expression should be final or effectively final而引发了方法参数值拷贝的问题
规避Variable used in lambda expression should be final or effectively final而引发了方法参数值拷贝的问题
203 0
|
安全
VS2019 error C4996: ‘scanf‘: This function or variable may be unsafe 错误
VS2019 error C4996: ‘scanf‘: This function or variable may be unsafe 错误
364 0
VS2019 error C4996: ‘scanf‘: This function or variable may be unsafe 错误
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
356 0
|
程序员 编译器 C语言
解决办法:undefined reference to symbol '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3
解决办法:undefined reference to symbol '_ZTVN10__cxxabiv117__class_type_infoE@@CXXABI_1.3
958 0