【发布时间】:2013-11-14 23:19:11
【问题描述】:
我有一个 ArrayQueue 我正在为 java 语言中的一个类实现。
我将事务对象存储在 ArrayQueue 中,但我陷入了 display() 方法(又名我自己的 toString())。但它只是返回引用。
这是我的方法:
//display the elements in the current queue
public String display() {
String result = "";
if(isEmpty()) {
throw new EmptyQueueException("Queue is empty.");
} else {
for (int i = 0; i < count; i++) {
result += "[" + Q[(front + i) % capacity] + "] ";
}
}
return result;
}
这是否意味着我的对象需要一个 toString() 方法并将其命名为:System.out.println(arrayqueue.display().toString())?
【问题讨论】: