-------------------------------------------------如图,StringBuffer的父类源码和jdk标明的不一样?而且AbstractStringBuilder这个类在jdk中查不到?

解决方案 »

  1.   

    JDK 里没有 AbstractStringBuilder 这个类楼主的第一个图片的信息从哪里来的?
      

  2.   

    AbstractStringBuilder在rt.jar的java.lang里面jdk文档没写这个抽象类是StringBuffer和stringBuilder的父类
      

  3.   

    继承自Object的那个你是从docs文档里面看到的吗?应该是文档写错了,源码里面的应该是继承自AbstractStringBuilder类的,不是在jdk中找不到这个AbstractStringBuilder类,而是在文档中找不到,你的文档有问题,jdk不可能没有。你不要把jdk和文档搞混淆了
      

  4.   


    StringBuilder 和 StringBuffer 都是直接继续自 Object,跟那什么抽象类没关系
      

  5.   


    StringBuilder 和 StringBuffer 都是直接继续自 Object,跟那什么抽象类没关系
    自己去源码。
      

  6.   


    StringBuilder 和 StringBuffer 都是直接继续自 Object,跟那什么抽象类没关系晕死JDK 的文档里说,StringBuilder 和 StringBuffer 都是直接继承自 Object,但打开这两个类的源代码,则都是继承自 AbstractStringBuilder。
    当然,可能这个AbstractStringBuilder 不是公共类,所以没有出现在API 文档里
      

  7.   

    以后这种问题自己可以attach源码看看。/*
     * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
     * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     *
     */package java.lang;import sun.misc.FloatingDecimal;
    import java.util.Arrays;/**
     * A mutable sequence of characters.
     * <p>
     * Implements a modifiable string. At any point in time it contains some
     * particular sequence of characters, but the length and content of the
     * sequence can be changed through certain method calls.
     *
     * @author      Michael McCloskey
     * @author      Martin Buchholz
     * @author      Ulf Zibis
     * @since       1.5
     */
    abstract class AbstractStringBuilder implements Appendable, CharSequence {
        /**
         * The value is used for character storage.
         */
        char[] value;    /**
         * The count is the number of characters used.
         */
        int count;    /**
         * This no-arg constructor is necessary for serialization of subclasses.
         */
        AbstractStringBuilder() {
        }    /**
         * Creates an AbstractStringBuilder of the specified capacity.
         */
        AbstractStringBuilder(int capacity) {
            value = new char[capacity];
        }    /**
         * Returns the length (character count).
         *
         * @return  the length of the sequence of characters currently
         *          represented by this object
         */
        public int length() {
            return count;
        }    /**
         * Returns the current capacity. The capacity is the amount of storage
         * available for newly inserted characters, beyond which an allocation
         * will occur.
         *
         * @return  the current capacity
         */
        public int capacity() {
            return value.length;
        }    /**
         * Ensures that the capacity is at least equal to the specified minimum.
         * If the current capacity is less than the argument, then a new internal
         * array is allocated with greater capacity. The new capacity is the
         * larger of:
         * <ul>
         * <li>The <code>minimumCapacity</code> argument.
         * <li>Twice the old capacity, plus <code>2</code>.
         * </ul>
         * If the <code>minimumCapacity</code> argument is nonpositive, this
         * method takes no action and simply returns.
         *
         * @param   minimumCapacity   the minimum desired capacity.
         */
        public void ensureCapacity(int minimumCapacity) {
            if (minimumCapacity > 0)
                ensureCapacityInternal(minimumCapacity);
        }    /**
         * This method has the same contract as ensureCapacity, but is
         * never synchronized.
         */
        private void ensureCapacityInternal(int minimumCapacity) {
            // overflow-conscious code
            if (minimumCapacity - value.length > 0)
                expandCapacity(minimumCapacity);
        }    /**
         * This implements the expansion semantics of ensureCapacity with no
         * size check or synchronization.
         */
        void expandCapacity(int minimumCapacity) {
            int newCapacity = value.length * 2 + 2;
            if (newCapacity - minimumCapacity < 0)
                newCapacity = minimumCapacity;
            if (newCapacity < 0) {
                if (minimumCapacity < 0) // overflow
                    throw new OutOfMemoryError();
                newCapacity = Integer.MAX_VALUE;
            }
            value = Arrays.copyOf(value, newCapacity);
        }    /**
         * Attempts to reduce storage used for the character sequence.
         * If the buffer is larger than necessary to hold its current sequence of
         * characters, then it may be resized to become more space efficient.
         * Calling this method may, but is not required to, affect the value
         * returned by a subsequent call to the {@link #capacity()} method.
         */
        public void trimToSize() {
            if (count < value.length) {
                value = Arrays.copyOf(value, count);
            }
        }    ……}
      

  8.   

    查看源码
    public final class StringBuilder
        extends AbstractStringBuilder
        implements java.io.Serializable, CharSequenceObject 是所有类的父类。
      

  9.   

    在jdkapi上面是有AbstractStringBuilder这个抽象父类的,abstract class AbstractStringBuilder implements Appendable, CharSequence