在Java中创建以数组作为参数的对象
好吧,我对此很陌生,甚至不确定我问的是正确的问题,但我想创建一个具有一些常规值(如字符串和整数等)的对象。但除此之外,我希望其中一个属性是像这样的字符串数组:
int hp =100;
int level =1;
int exp=0;
String[] items = {"hpPot","blank","blank","blank","blank"};
return new player(level, exp, hp, name, items[] );
}
这不起作用,至少我想知道到底为什么。
谢谢。
Ok I'm really new to this and am not even sure I'm asking the right question but I want to create an object that has some regualr values like strings and ints etc. But in addition I want one of the properties to be an array of strings like this:
int hp =100;
int level =1;
int exp=0;
String[] items = {"hpPot","blank","blank","blank","blank"};
return new player(level, exp, hp, name, items[] );
}
This doesn't work and at the least I'd like to know exactly why.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
传递
数组
时不要使用下标运算符
while passing
array
don't usesubscript operator