Java语言!!求解!!请大神简单翻译一下!!
AgentList<GoToTrain>goToTrain=null;switch(trainIndex){case0:{goToTrain=goToTrain1;bre...
AgentList<GoToTrain> goToTrain = null;
switch(trainIndex)
{
case 0:
{
goToTrain = goToTrain1;
break;
}
case 1:
{
goToTrain = goToTrain2;
break;
}
}
for(GoToTrain goTo: goToTrain)
{
goTo.board();
} 展开
switch(trainIndex)
{
case 0:
{
goToTrain = goToTrain1;
break;
}
case 1:
{
goToTrain = goToTrain2;
break;
}
}
for(GoToTrain goTo: goToTrain)
{
goTo.board();
} 展开
2个回答
展开全部
先定义一个AgentList<GoToTrain> 类型的变量,取名goToTrain,注意是泛型<GoToTrain>,AgentList也许是你自定义的对象类型(引用类型,类类型),也许是你打错了(猜想是ArrayList);switch(trainIndex):是对变量trainIndex进行判断,当trainIndex的值为0时,将 goToTrain1的值递给goToTrain(是值传递还是引用传递你自己判断),break结束,case1同理;最后是foreach遍历goToTrain ,调用它的方法.board();。。。。。。。。。。。。纯粹手敲,给个好评哦,
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询