treemap中的tailmap是返回大于某个key的子map
查看源代码,不断的trace发现tailmap这个方法在调用treemap的内部类
最后是return new navigablesubmap(xxxx)
在这个this.m=m后,debug看到的this变量是
>Exception occurred in target VM:  
java.lang.NullPointerException: 
at TreeMap.compare(TreeMap.java:1192)
at TreeMap.getHigherEntry(TreeMap.java:460)
at TreeMap$NavigableSubMap.absLowest(TreeMap.java:1323)
at TreeMap$AscendingSubMap$AscendingEntrySetView.iterator(TreeMap.java:1758)
at TreeMap$NavigableSubMap$EntrySetView.size(TreeMap.java:1531)
at TreeMap$NavigableSubMap.size(TreeMap.java:1404)
at TreeMap$NavigableSubMap.<init>(TreeMap.java:1274)
at TreeMap$AscendingSubMap.<init>(TreeMap.java:1705)
at TreeMap.tailMap(TreeMap.java:909)
at TreeMap.tailMap(TreeMap.java:944)
at NewClass1.main(NewClass1.java:22)
<
在this.toEnd=toEnd后,再看this变量,这个exception已经没了,并且this中是一个想要的submap了(既结果)
求教这个是怎么实现的?另外exception里面为啥会出现at TreeMap$NavigableSubMap.size(TreeMap.java:1404)
NavigableSubMap(TreeMap<K,V> m,
                        boolean fromStart, K lo, boolean loInclusive,
                        boolean toEnd,     K hi, boolean hiInclusive) {
            if (!fromStart && !toEnd) {
                if (m.compare(lo, hi) > 0)
                    throw new IllegalArgumentException("fromKey > toKey");
            } else {
                if (!fromStart) // type check
                    m.compare(lo, lo);
                if (!toEnd)
                    m.compare(hi, hi);
            }            this.m = m;
            this.fromStart = fromStart;
            this.lo = lo;
            this.loInclusive = loInclusive;
            this.toEnd = toEnd;
            this.hi = hi;
            this.hiInclusive = hiInclusive;
        }