java中Integer中的hashCode方法

本文介绍了Java中Integer类的hashCode方法实现原理,该方法简单直接返回Integer对象所表示的int值,同时也重写了toString方法。

java中Integer中的hashCode方法,是重写的,下面抄了部分Integer类的实现

    public String toString() {
	return String.valueOf(value);
    }

    /**
     * Returns a hash code for this <code>Integer</code>.
     *
     * @return  a hash code value for this object, equal to the 
     *          primitive <code>int</code> value represented by this 
     *          <code>Integer</code> object. 
     */
    public int hashCode() {
	return value;
    }


我们可以看到,实际上,Integer就是很简单的重写了一下toString和hashCode方法,就是返回本身的值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值