Why does the default Object.toString() include the hashcode?

前端 未结 3 703
别跟我提以往
别跟我提以往 2020-11-22 09:40

If you execute:

System.out.println(someObj.toString());

you probably see the output like

someObjectClassname@hashcod

3条回答
  •  忘掉有多难
    2020-11-22 09:54

    Adding something useful.

    Some newbies may be confused as to why the hascode value returned via toString() is different than what is returned via hashCode(). This is because the toString() method returns a hex representaion of the same hashcode .

    Integer.toHexString(object.hashCode()); will return the same value returned by object.toString().

提交回复
热议问题