gpt4 book ai didi

执行@number时的Java链接列表错误消息

转载 作者:行者123 更新时间:2023-12-02 08:11:08 27 4
gpt4 key购买 nike

每当我运行该方法时,我都会收到一个带有数字的错误

以下是我的代码。

public String getAccount()
{
String s = "Listing the accounts";
for(List l:lists)
s+=" "+list.toString;
Return s;
}

当我运行此方法时,我得到以下信息:

List@some numbers

对于 List 类,我只有一个构造函数,它将解析的变量指定为局部变量。

有人知道这意味着什么吗?

最佳答案

这意味着您尚未重写(显然)自定义 List 类中的 toString 方法。默认实现 ( Object.toString ) 显示如上所示的输出:

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())

您应该在自定义类中重写toString,以便提供所需的输出。

关于执行@number时的Java链接列表错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7403269/

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