什么是Java中的钻石操作? [英] What is diamond Operator in java?

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

问题描述

我有型patient_class和ArrayList的类型的ArrayList已经被黄色下划线和IDE提到新的前pression冗余类型参数(采用金刚石操盘手)。

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 used diamond operator instead ? is it a must? will i get any date lose or any other problem when storing records to the arraylist ?

下面是我的ArrayList: -
公共类Register_newpatient扩展javax.swing.JFrame中的{

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 is a diamond operator actually is.

推荐答案

不要worry.Its不是 JAVA的evil.Its功能7

Don't worry.Its not an evil.Its feature of JAVA 7.

钻石运营商的目的是简化泛型类的实例化。例如,而不是

Purpose of the diamond operator is to simplify instantiation of generic classes. For example, instead of

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

与钻石经营者,我们只能写

with the diamond operator we can write only

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

如果您想了解更多关于它,想使用它,请快速浏览一下的 这里 并决定是否对你或没有用处。

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天全站免登陆