查看: 1096|回复: 5
收起左侧

[已解决] 一段死活都不知道错在哪里的java代码,各位大虾帮忙啊

 关闭 [复制链接]
chixyang
发表于 2009-12-23 20:55:28 | 显示全部楼层 |阅读模式
/**
  * Returns <code>true</code> if the specified array list contains a
  * student whose id matches the specified ID.
  *
  * @param arrayList  an array list of <code>Student</code> objects.
  * @param id  a student ID.
  * @return  <code>true</code> if the specified array list contains a
  *          student whose ID matches the specified ID;
  *          <code>false</code> otherwise.
  */
public static boolean hasStudent(
  ArrayList<Student>  arrayList,
  int  id)  {
      for(Student student:arrayList)
   if(student.getId()==id)
                return true;
   
  
}
就是这个,上面是对这段代码的注释,下面的这段代码却老是显示“this method should return a result of type boolean”,可是明明有返回啊,“return true”不就是吗...看了好久始终不明白...请各位高手够看看,帮忙解答一下啊,谢谢了(我是用eclipse编译的)
伊の星
发表于 2009-12-23 23:30:34 | 显示全部楼层
else
return false
chixyang
 楼主| 发表于 2009-12-24 08:49:46 | 显示全部楼层
终于有人回复了...只是,else return false 的话,这个方法本身就有问题了...
伊の星
发表于 2009-12-24 09:39:24 | 显示全部楼层
你如何添加,然后提示什么错误?
heje
发表于 2009-12-24 12:42:39 | 显示全部楼层
* @return  <code>true</code> if the specified array list contains a
  *          student whose ID matches the specified ID;
  *          <code>false</code> otherwise.
你的注释里不是说得很明白了?
chixyang
 楼主| 发表于 2009-12-24 12:56:58 | 显示全部楼层
哦,不好意思,知道了,确实需要return false;否则如果不包括匹配的ID的话就没有返回了...谢谢二位
您需要登录后才可以回帖 登录 | 快速注册

本版积分规则

手机版|杀毒软件|软件论坛| 卡饭论坛

Copyright © KaFan  KaFan.cn All Rights Reserved.

Powered by Discuz! X3.4( 沪ICP备2020031077号-2 ) GMT+8, 2025-6-30 15:54 , Processed in 0.126831 second(s), 17 queries .

卡饭网所发布的一切软件、样本、工具、文章等仅限用于学习和研究,不得将上述内容用于商业或者其他非法用途,否则产生的一切后果自负,本站信息来自网络,版权争议问题与本站无关,您必须在下载后的24小时之内从您的电脑中彻底删除上述信息,如有问题请通过邮件与我们联系。

快速回复 客服 返回顶部 返回列表