java '(' 或 '[' 应为
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4302659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'(' or '[' Expected
提问by Chris
I am getting the following error when trying to compile my program.
尝试编译我的程序时出现以下错误。
'(' or '[' Expected.
'(' 或 '[' 预期。
public AccountArrayList()
{
// line one below is the hi-lighted code
ArrayList accounts = new ArrayList;
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add("1");
accounts.add(5,"900");
}
Thank you.
谢谢你。
回答by Yuval Adam
You're missing parenthesis on the constructor:
您在构造函数上缺少括号:
ArrayList accounts = new ArrayList();
回答by RoflcoptrException
Your constructor is wrong. It has to be;
你的构造函数是错误的。它一定要是;
ArrayList accounts = new ArrayList();
回答by Buhake Sindi
回答by Lukas Eder
Well, you can't construct an ArrayList
like this.
Try
好吧,你不能构造ArrayList
这样的。尝试
new ArrayList()
instead
反而
回答by daveb
It's the call to the constructor that's the problem, it should be
问题在于调用构造函数,应该是
ArrayList accounts = new ArrayList();
Also, you would do well to specify it like this:
此外,您最好像这样指定它:
ArrayList<String> accounts = new ArrayList<String>();
Because then the compiler will prevent you from adding Integers to it (for example) rather than Strings.
因为这样编译器将阻止您向其中添加整数(例如)而不是字符串。