Java接口自动化框架:maven编译警告解决之-Xlint:unchecked以及使用了未经检查或不安全的操作

1、问题:mvn 编译或执行时告警某些输入文件使用了未经检查或不安全的操作

通过mvn命令来编译代码时,如mvn clean compile,有时会出现WARNING编译警告,只是提示某个类,但是没有提示具体哪行代码,提示加上-Xlint:unchecked来查看详细信息。

 按提示加上:mvn clean compile -Xlint:unchecked 进行编译,提示:没有lint控件

 2、解决办法

2.1、在pom.xml中加上<compilerArgument>

<plugin>
    <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <compilerArgument>-Xlint:unchecked</compilerArgument>
    </configuration>
</plugin>

再次编译mvn clean compile,可以查看到哪个类的哪行有问题。

  2.2、修改如下:

HashMap<> AlgorithmsJson=getAlgorithmsJson(AlgorithmTypeList);
public HashMap<String,String> getAlgorithmsJson(List<String> AlgorithmTypeList){}
修改成:
HashMap<String,String> AlgorithmsJson=getAlgorithmsJson(AlgorithmTypeList);
public HashMap<String,String> getAlgorithmsJson(List<String> AlgorithmTypeList){}

其他的修改:

Map<String, Object> map = new LinkedHashMap();
改成:
Map<String, Object> map = new LinkedHashMap<>();

问题:对作为原始类型com.mongodb.client.MongoCollection的成员的insertOne(TDocument)的调用未经过检查

MongoCollection dbColl= mongoClient.getDatabase(dbName).getCollection(coll);
public List<AoeData> query(MongoCollection collection){}
修改:
MongoCollection<Document> dbColl= mongoClient.getDatabase(dbName).getCollection(coll);
public List<AoeData> query(MongoCollection<Document> collection){}
 

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宁宁可可

您的鼓励是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值