解决在java中输出的变量的内存

时间:2021-10-08 23:07:25

This code below is meant to populate the combo box with available times according to the selected date.

下面的代码用于根据所选日期使用可用时间填充组合框。

However for some reason the combo box is storing the memory address of the data example:

但是由于某种原因,组合框正在存储数据示例的内存地址:

Restaurant.Time@1a28362
Restaurant.Time@5fcf29
...

I know its getting the right times. But how do I actual print out the actual item?

我知道它正确的时间。但是我如何实际打印出实际物品?

TimeList times = dbConnector.selectTimes(lblDay.getText());//lblDay stores the date from the jCalendar button
cmbNewResTimes.removeAllItems();
for (int pos1 = 0; pos1 < times.size(); pos1++) {
    cmbNewResTimes.addItem(times.getTimeAt(pos1).toString());
}

2 个解决方案

#1


7  

Add Object instance

Firstly, change it to:

首先,将其更改为:

// add the Object, rather than the String representation.
cmbNewResTimes.addItem(times.getTimeAt(pos1));  

Set a renderer

Then set a renderer, see:

然后设置渲染器,请参阅:

#2


2  

All it means is that Restaurant.Time doesn't override the toString() method, so the default implementation provided by Object is used.

这意味着,Restaurant.Time不会覆盖toString()方法,因此使用了Object提供的默认实现。

If you want the output to look differently, you'll need to override Restaurant.Time.toString().

如果您希望输出看起来不同,则需要覆盖Restaurant.Time.toString()。

#1


7  

Add Object instance

Firstly, change it to:

首先,将其更改为:

// add the Object, rather than the String representation.
cmbNewResTimes.addItem(times.getTimeAt(pos1));  

Set a renderer

Then set a renderer, see:

然后设置渲染器,请参阅:

#2


2  

All it means is that Restaurant.Time doesn't override the toString() method, so the default implementation provided by Object is used.

这意味着,Restaurant.Time不会覆盖toString()方法,因此使用了Object提供的默认实现。

If you want the output to look differently, you'll need to override Restaurant.Time.toString().

如果您希望输出看起来不同,则需要覆盖Restaurant.Time.toString()。