Entry

来源:互联网 发布:java导出excel xlsx 编辑:程序博客网 时间:2024/06/10 03:38

Entry类

开心一笑

一孩子数学成绩不好,有次考试只考了8分,为了不挨揍他偷偷地加了一个0,回家后老妈看着我的试卷问他:“你是不是改分数了?”他理直气壮地说没有,老妈边揍边骂:“让你考个08分,让你考个08分。”

自我介绍

我是一个静态类,实现Map.Entry< K ,V>,通过我可以构成一个单向链表,在java帮助文档中没有我的地位,我只是一个内部类。

//源码private static class Entry<K,V> implements Map.Entry<K,V> {        int hash;        final K key;        V value;        //next 可构成单向链表        Entry<K,V> next;        protected Entry(int hash, K key, V value, Entry<K,V> next) {            this.hash = hash;            this.key =  key;            this.value = value;            this.next = next;        }        protected Object clone() {            return new Entry<>(hash, key, value,(next==null ? null : (Entry<K,V>) next.clone()));        }        // Map.Entry Ops        public K getKey() {            return key;        }        public V getValue() {            return value;        }        public V setValue(V value) {            if (value == null)                throw new NullPointerException();            V oldValue = this.value;            this.value = value;            return oldValue;        }        public boolean equals(Object o) {            if (!(o instanceof Map.Entry))                return false;            Map.Entry<?,?> e = (Map.Entry)o;            return key.equals(e.getKey()) && value.equals(e.getValue());        }        public int hashCode() {            return hash ^ value.hashCode();        }        public String toString() {            return key.toString()+"="+value.toString();        }    }
0 0
原创粉丝点击