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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:28:24  来源:igfitidea点击:

Java program uses unchecked or unsafe operations

javaarrayscompiler-errors

提问by Eri Agbayani

I was writing a program in our activity in school and when I compile I get the following error:

我在学校的活动中编写程序,编译时出现以下错误:

enter image description here

在此处输入图片说明

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?

更多信息什么是原始类型,我们为什么不应该使用它?