java编译时出现使用了未经检查或不安全的操作解决方法
时间:2022-05-21 00:21:21
在本人用editplus写java文件时碰到的问题。
import java.util.*;
class collection{
public static void main(String[] args) {
Collection c1=new ArrayList(25);
c1.add(new String("one"));
c1.add(new String("two"));
String s="three";
c1.add(s);
for (Iterator i=c1.iterator();i.hasNext();)
{
System.out.println(i.next());
}
}
}
然后查找到以下原因,这是转自别人的。
在编译java源文件时,你使用的是jdk1.5或以上时,可能出现这个问题。(使用了未经检查或不安全的操作;请使用 -Xlint:unchecked 重新编译。)
原因是jdk1.5里的集合类的创建和jdk1.4里有些区别,主要是jdk1.5里增加了泛型,也就是说可以对集合里的数据进行检查。在jdk1.5以前,如果没有指定参数类型,则 JDK 1.5 编译器由于无法检查 给出的参数是否合乎要求,而报告 unchecked 警告,这并不影响运行。按照提示,编译是指定参数即可取消这样的警告。或者为其制定类型参数。
List temp = new ArrayList ();
temp.add("1");
temp.add("2");
修改为
List <String> temp = new ArrayList <String> ();
temp.add("1");
temp.add("2");
然后修改代码为
import java.util.*;
class collection{
public static void main(String[] args) {
Collection<String> c1=new ArrayList<String>(25);
c1.add(new String("one"));
c1.add(new String("two"));
String s="three";
c1.add(s);
for (Iterator i=c1.iterator();i.hasNext();)
{
System.out.println(i.next());
}
}
}
标签:java,编译
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
c# winform多线程的小例子
2023-01-05 07:11:44
![](https://img.aspxhome.com/file/2023/5/108685_0s.png)
C#的3DES加密解密算法实例代码
2023-09-23 01:10:19
Spring事务事件监控的实现
2022-11-28 06:19:13
基于Spring Boot不同的环境使用不同的配置方法
2022-11-06 13:21:20
webuploader 实现图片批量上传功能附实例代码
2022-12-03 09:13:34
![](https://img.aspxhome.com/file/2023/8/67148_0s.png)
C#实现简单的汽车租赁系统
2022-08-17 00:51:52
![](https://img.aspxhome.com/file/2023/1/100201_0s.png)
深入多线程之:内存栅栏与volatile关键字的使用分析
2021-05-29 10:02:56
SpringMvc MultipartFile实现图片文件上传示例
2022-07-30 16:40:45
![](https://img.aspxhome.com/file/2023/5/113455_0s.png)
Android实现动态添加数据与堆叠折线图详解流程
2021-09-27 17:50:49
![](https://img.aspxhome.com/file/2023/0/106000_0s.gif)
Java Lambda表达式实例解析原理
2022-11-02 08:11:02
Mybatis通过Spring完成代理类注入的流程分析
2023-10-25 00:55:55
![](https://img.aspxhome.com/file/2023/5/70575_0s.png)
c#动态加载卸载DLL的方法
2023-06-08 08:18:08
解决mybatis-plus3.1.1版本使用lambda表达式查询报错的方法
2022-03-19 03:55:09
Java实现的RSA加密解密算法示例
2022-05-03 09:20:38
C#使用三层架构开发Winform的详细案例
2023-08-08 03:22:24
![](https://img.aspxhome.com/file/2023/9/67569_0s.jpg)
Spring Boot 中的Servlet简单使用
2023-01-28 03:08:06
![](https://img.aspxhome.com/file/2023/9/67139_0s.png)
Android使用CrashHandler来获取应用的crash信息的方法
2023-07-25 20:27:38
不用IDE写C#的Hello World的方法
2022-01-25 19:24:58
![](https://img.aspxhome.com/file/2023/1/91281_0s.png)
Java通过PropertyDescriptor反射调用set和get方法
2023-10-11 19:34:17
java如何使用自己的maven本地仓库详解
2022-08-01 12:13:44