enjoy_lifestyle 2015-04-15 10:26 采纳率: 0%
浏览 1525

一个小程序的问题——

//这是一个关于个人信息管理系统的简单实现
//下面的是自己创建的收集信息的容器
//主函数和其他子类没有问题
public class PIMCollection implements Collection {
ArrayList arr = newInstance();
ArrayList tmp;
private ArrayList newInstance()
{
return new ArrayList();
}
//其中省略了实现的方法,都没有编译错误
public Collection getNote(){
tmp = newInstance();
for(T obj:arr)
{
if(obj.getClass().getName().equals("hw_1.PIMNote"))
tmp.add(obj);
}
if(tmp.isEmpty())
return null;
else
return tmp;
}
public Collection getTodo(){
tmp = newInstance();
for(T obj:arr)
{
if(obj.getClass().getName().equals("hw_1.PIMtodo"))
tmp.add(obj);
}
if(tmp.isEmpty())
return null;
else
return tmp;
}
public Collection getAppointment(){
tmp = newInstance();
for(T obj:arr)
{
if(obj.getClass().getName().equals("hw_1.PIMAppointment"))
tmp.add(obj);
}
if(tmp.isEmpty())
return null;
else
return tmp;
}
public Collection getContact(){
tmp = newInstance();
for(T obj:arr)
{
if(obj.getClass().getName().equals("hw_1.PIMContact"))
tmp.add(obj);
}
if(tmp.isEmpty())
return null;
else
return tmp;
}
//输出各子类中带有date的类
public Collection getItemForDate() throws NoSuchFieldException, SecurityException{
tmp = newInstance();
for(T obj:arr)
{
if(obj.getClass().getDeclaredField("date")!=null)
tmp.add(obj);
}
if(tmp.isEmpty())
return null;
else
return tmp;
}
}
/*
*main函数中关于上面的输出形式为
*/case "List" :
{
System.out.println("There are "+i+" items");
System.out.print("note Item 为");
System.out.println(c.getNote());
System.out.print("todo Item 为");
System.out.println(c.getTodo());
System.out.print("appointment Item 为");
System.out.println(c.getAppointment());
System.out.print("contact Item 为");
System.out.println(c.getContact());
System.out.print("包含date feild Item 为");
System.out.println(c.getItemForDate());
break;
}
//输出为:
here are 3 items
note Item 为[note nnvbv iiii]
todo Item 为[todu 13123 qqqqqq ppp, todu 3534534 wwwwww oooo]
appointment Item 为null
contact Item 为null
包含date feild Item 为---Enter a command (suported commands are List Create Save Quit)---
为什么最后关于date的函数没有输出?如果没有date选项的话也应该返回null的,为什么没有任何返回值?
本人比较穷,没有金币,请大神解答谢谢

  • 写回答

2条回答 默认 最新

  • threenewbee 2015-04-15 17:46
    关注

    因为你返回的是Collection不是Date

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?