项目的异常环境:
项目类型:基本的gradle构建工程,加一些junit测试!
gradle版本:gradle 6.0 / gradle5.6.3 都有实践过!
注:下载时只要下载xxxx-bin.zip就可以使用!
Junit版本:Junit5 。
Junit5的Gradle依赖:
testImplementation 'org.assertj:assertj-core:3.11.1'
testCompile('org.mockito:mockito-junit-jupiter:2.18.3')
// Deprecated. Target to remove powermock & junit4
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0-beta.5'
// Deprecated. Target to remove powermock & junit4
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0-beta.5'
// Deprecated. Target to remove powermock & junit4
testCompile group: 'org.powermock', name: 'powermock-core', version: '2.0.0-beta.5'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.19.0'
testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.5.2")
问题展示:
原因分析及相应的解决方法:
原因分析:
注意: 一些输入文件 使用了未经检查或不安全的操作。
注意: 要了解详细信息,请使用 -Xlint:unchecked 重新编译。
其实是因为用到了JAVA5.0的泛型,而5.0的泛型不做类型检查。
例如:ArrayList list =new ArrayList();
list.add("apple");
这样由于泛型问题就会出现这种警告!
解决方法:
1)在方法的前面加上注解:@SuppressWarnings("unchecked");
2)声明泛型类型,例如:ArrayList<Object> list = new ArrayList<Object>();
3)使用1.4兼容JDK对项目进行编译:javac -source 1.4 XXX.java;
4)查看详细的警告信息:javac Xlint:unchecked XXX.java;