什么是Java中的钻石运算符? [英] What is the diamond operator in Java?

查看:165
本文介绍了什么是Java中的钻石运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类型为patient_class的arraylist,并且arraylist类型用黄色加下划线,IDE提到了新表达式中的冗余类型参数(使用菱形运算符代替)。

I have an arraylist with type patient_class and the arraylist type has been underlined in yellow and the IDE has mentioned "redundant type arguments in new expression (use diamond operator instead)".

我的问题是:我应该使用钻石操作员吗?这是必须的吗?将记录存储到arraylist时,我会收到任何数据丢失或任何其他问题吗?

My problem is: Should I use the diamond operator instead? Is it a must? Will I get any data loss or any other problem when storing records to the arraylist?

这是我的arraylist:

Here is my arraylist:

public class Register_newpatient extends javax.swing.JFrame {

    public Register_newpatient() {
        initComponents();
        groupbutton();
    }

    public void groupbutton()
    {
        ButtonGroup bg1=new ButtonGroup();

        bg1.add(rbopd);
        bg1.add(rbinpatientcare);
        bg1.add(rbboth);
    }

    all_error_handling checkerror = new all_error_handling();
    JFrame frame = new JFrame();
    static ArrayList<patient_class>patientlist = new ArrayList<patient_class>();

老实说我不知道​​钻石运营商到底是什么。

To be honest I have no idea what a diamond operator actually is.

推荐答案

别担心。这不是邪恶的。这是Java 7的特性。

Don't worry. It's not an evil. It's feature of Java 7.

菱形运算符的目的是简化泛型类的实例化。

The purpose of the diamond operator is to simplify instantiation of generic classes.

例如,代替

List<Map<Integer,Set<String>>> p = new ArrayList<Map<Integer,Set<String>>>();

我们只能写钻石算子

List<Map<Integer,Set<String>>> p = new ArrayList<>();

如果您想了解更多信息并希望使用它,请快速查看 here 并确定它是否有用给你与否。

If you want to know more about it and want to use it, please have a quick look here and decide whether it's useful to you or not.

这篇关于什么是Java中的钻石运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆