gpt4 book ai didi

java - 在java中传递对象数组并将对象数组保存在被调用的方法中

转载 作者:行者123 更新时间:2023-12-01 10:06:56 26 4
gpt4 key购买 nike

我编写了一些代码来返回一个对象数组。如何在被调用的方法中保存这些对象?

   public Ticket[] getOpenTicket() {
int ticketcount = 0;
for (int i = 0; i < ticket.length; i++) {
if (ticket[i] != null && ticket[i].getResolvedBy() == null) {
ticketcount = ticketcount + 1;
// System.out.println("Ticket raised by : " +
// ticket[i].getTicketno());
}
}

Ticket[] opentickets = new Ticket[ticketcount];
for (int i = 0; i < ticket.length; i++) {
if (ticket[i].getResolvedBy() == null) {
opentickets[i] = ticket[i];
}
}
return opentickets;

}

这是我调用 openticket 的被调用函数:

TicketDaoMemImpl tdmi=new TicketDaoMemImpl();
Ticket [] obj1=tdmi.getOpenTicket();

谢谢

最佳答案

这不应该看起来更像这样吗:

public class CheckTicket {
public Ticket [] openTicket() {
return arrayOfTickets; // wherever that comes from
}
}

CheckTicket cc = new CheckTicket();
Ticket[] t1 = cc.openTicket();

关于java - 在java中传递对象数组并将对象数组保存在被调用的方法中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36376527/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com