ArrayList显式类型参数字符串可以替换为<>吗? [英] ArrayList explicit type argument string can be replaced with <>?
问题描述
一个新手在这里! 我正在尝试在Android Studio上创建一个arrayList:
a newbie here! I am trying to create an arrayList on Android Studio :
ArrayList<String> family = new ArrayList<String>();
但是它给我一个警告:显式类型参数字符串可以替换为<>"和此检查报告所有具有类型参数的新表达式,都可以替换为菱形类型<>".我试图忽略它,因为它只是一个警告,但是我无法使用".add"将任何元素添加到Arraylist中,所以我认为甚至没有创建Arraylist.我尝试重新启动Android Studio和其他内容,但没有任何效果!谢谢您的宝贵时间.
but it gives me a warning "Explicit type argument string can be replaced with <>" and "This inspection reports all new expressions with type arguments which can be replaced with diamond type <>". I tried to ignore it because it is just a warning but I couldn't add any elements to the Arraylist using ".add" so I assume the Arraylist wasn't even created. I tried restarting Android Studio and stuff but nothing worked! Thanks for your time.
主要问题是当我使用添加"时,它说它无法解析符号添加". 例子:
the main problem is that when I use "add" it said that it cannot resolve symbol 'add'. example :
family.add("jacob");
已解决:感谢大家的回答,我卸载了Android Studio,然后重新安装了它,现在不再遇到问题了!
SOLVED: Thanks everyone for your answers, I uninstalled Android Studio and then reinstalled it and I am not encountering the problem anymore!
推荐答案
代替写作
ArrayList<String> family = new ArrayList<String>();
你可以写
ArrayList<String> family = new ArrayList<>();
如果您使用的是Java7.
if you're using Java7.
它被称为钻石运算符,它只是语法糖.您可以放心地忽略它.
It's called the diamond operator, and it's just syntactic sugar. You can safely ignore it.
这篇关于ArrayList显式类型参数字符串可以替换为<>吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!