消除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));
相关文章
|
2月前
Flutter-解决Try catch出现异常:type ‘_TypeError‘ is not a subtype of type ‘Exception‘ in type cast
Flutter-解决Try catch出现异常:type ‘_TypeError‘ is not a subtype of type ‘Exception‘ in type cast
56 1
|
2月前
|
Dart 开发工具
解决升级Flutter3.0后出现警告Operand of null-aware operation ‘!‘ has type ‘WidgetsBinding‘ which excludes null
解决升级Flutter3.0后出现警告Operand of null-aware operation ‘!‘ has type ‘WidgetsBinding‘ which excludes null
27 1
|
12月前
|
存储 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
168 0
【Java异常】Variable used in lambda expression should be final or effectively final
|
5月前
|
数据库
Greenplum【异常 03】COPY命令报错 > ERROR: invalid input syntax for type double precision: ““(问题分析及解决方案)数据去重
Greenplum【异常 03】COPY命令报错 > ERROR: invalid input syntax for type double precision: ““(问题分析及解决方案)数据去重
171 0
|
10月前
|
安全 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
162 0
|
Java 编译器
规避Variable used in lambda expression should be final or effectively final而引发了方法参数值拷贝的问题
规避Variable used in lambda expression should be final or effectively final而引发了方法参数值拷贝的问题
187 0
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
308 0
Python bug:ValueError: invalid literal for int() with base 10: ''
Python bug:ValueError: invalid literal for int() with base 10: ''
|
JSON 数据格式
sonar代码质量检测告警“static“ base class members should not be accessed via derived types
sonar代码质量检测告警“static“ base class members should not be accessed via derived types
802 0
sonar代码质量检测告警“static“ base class members should not be accessed via derived types