Java 程序使用未经检查或不安全的操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36113596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java program uses unchecked or unsafe operations
提问by Eri Agbayani
I was writing a program in our activity in school and when I compile I get the following error:
我在学校的活动中编写程序,编译时出现以下错误:
I am also using notepad++ to compile This is the code:
我也是用notepad++编译的,代码如下:
import java.util.ArrayList;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
ArrayList arrayList = new ArrayList();
arrayList.add("A");
arrayList.add("B");
arrayList.add("C");
arrayList.add("D");
arrayList.add("E");
System.out.println("Before Reverse Order: " + arrayList);
Collections.reverse(arrayList);
System.out.println("After Reverse Order: " + arrayList);
}
}
I am new to learning java so any help is appreciated thank you!
我是学习 Java 的新手,因此感谢您的帮助!
采纳答案by Yassin Hajaj
You are using raw typeswith the ArrayList
您正在使用的原始类型与ArrayList
replace it with
将其替换为
ArrayList<String> arrayList = new ArrayList<>();
More info: What is a raw type and why shouldn't we use it?
更多信息:什么是原始类型,我们为什么不应该使用它?