为什么显式类型参数应该用菱形代替? [英] Why explicit type argument should be replaced by diamond?

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

问题描述

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

I'm using Android Studio and I write this :

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

我有这条消息:

显式类型参数 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>>();

对比

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

我认为你会选择第二个选项

I think you would go for the second option

这篇关于为什么显式类型参数应该用菱形代替?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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