为什么明确的类型参数应该被钻石取代? [英] Why explicit type argument should be replaced by diamond?

查看:139
本文介绍了为什么明确的类型参数应该被钻石取代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android Studio,我写这个:

I'm using Android Studio and I write this :

List<Button> buttons = new ArrayList<Button>();

我收到此消息:


显式类型参数按钮应替换为<>

Explicit type argument Button should be replaced by <>

我很好奇,为什么会更好改为使用钻石?

I'm curious, why would it be better to use diamond instead ?

List<Button> buttons = new ArrayList<>();

编辑:

我完全不同意这些副本!我之前看到了这个答案,它将显式参数与无参数进行比较,而我将显式参数与隐式参数进行比较!

EDIT :
I don't agree with the duplicate at all ! I saw that answer before and it compares explicit argument to no argument at all, whereas I compare explicit argument to implicit argument !

推荐答案

它不那么冗长,请考虑以下内容

It is less verbose, consider the following

Map<String,List<String>> map = new HashMap<String,List<String>>();

vs

Map<String,List<String>> map = new HashMap<>();

我想你会选择第二个选项

I think you would go for the second option

这篇关于为什么明确的类型参数应该被钻石取代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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