当前位置: 代码迷 >> Java相关 >> [求助]关于System.out.println(object)的奇怪现象
  详细解决方案

[求助]关于System.out.println(object)的奇怪现象

热度:606   发布时间:2006-04-02 18:00:00.0
[求助]关于System.out.println(object)的奇怪现象
1。class Attrubute{
.......
public static void main(String[] ops)
{
Attribute data;
data=new Attribute("date", "yyyy-MM-dd HH:mm:ss");
System.out.println(data);
//显示@attribute date date 'yyyy-MM-dd HH:mm:ss'
String local_string;
Object local_obj;
local_obj=data;
local_string = local_obj.getClass().getName();
local_string+="@";
local_string = Integer.toHexString(local_obj.hashCode());
System.out.println(local_string);
//显示pro_1.Attribute@110b053

}
}
2.object.toString()
{
return getClass().getName() + "@" + Integer.toHexString(hashCode());
}
3。为什么在1中同样的代码功能段却显示了不同的结果
请大虾指教
搜索更多相关的解决方案: object  println  现象  System  

----------------解决方案--------------------------------------------------------

看你在class Attrubute中有没有实现toString的功能,如果没有的话,就会按照Object的方法来输出


----------------解决方案--------------------------------------------------------
谢谢,正是这个原因
----------------解决方案--------------------------------------------------------
  相关解决方案