java - ArrayList: How to arraylist.set when you have multiple setters
问题描述
I currently have 2 classes. My bot:
public class Bot {
private int X;
private int Y;
private int degress;
public int getX() {
return X;
}
public int getY() {
return Y;
}
public int getDegress() {
return degress;
}
public void setX(int X) {
this.X = X;
}
public void setY(int Y) {
this.Y = Y;
}
}
and my main code.. the problem i am having is when trying to set the degrees in my main class. What I am trying to do is something similar to:
bots.set(bots.get(1).getDegress(),+1);
but gives me this error "The method set(int, Bot) in the type ArrayList is not applicable for the arguments (int, int)"
and how my ArrayList looks like
public static ArrayList<Bot> bots = new ArrayList<Bot>();
So to sum it up. How could i come about to change X, Y or Degress with the bots.set?
解决方案
bots.set
是一种ArrayList
方法。要改变一个Bot
实例,你必须调用一个Bot
方法。
它应该是:
Bot bot = bots.get(1);
bot.setDegrees(bot.getDegrees()+1);
或者,当然,你的课堂上需要一个setDegrees
方法。Bot
推荐阅读
- python - Python - 计算列表列表中的出现次数
- python - 在 if then 语句中定义、加/减(彼此)、打印和定义变量
- apache - AH01630:客户端被服务器配置拒绝,但要求所有已设置(Apache 2.4,CentOs)
- vba - 运行时错误:Excel 宏 2016 中的“9”下标超出范围
- asp.net-core - 使用 OpenId 服务器的外部声明
- python - 使用 Windows 命令提示符或 PowerShell 在 Spyder 中运行脚本
- java - Hibernate 具有不同键类型的一对一映射
- javascript - C# 和 javascript 之间的 ECDH
- dataframe - 在 Julia 1 中将缺失转换为数值
- javascript - 如何将 JQuery 的 appendTo 方法与一长串元素一起使用,其中包含单引号/双引号的组合