-------------------------------------------------如图,StringBuffer的父类源码和jdk标明的不一样?而且AbstractStringBuilder这个类在jdk中查不到?
解决方案 »
- 发现java io流中mark()和reset()方法没用,求曾姐····
- Java可以监控键盘输入吗?
- 高分求算法
- java 获取当前时间后,怎么计算得到延迟3小时候的时间
- 关于设置swing快捷键的问题!! 当设ESC为快捷键时,好像没什么效果
- (.)(.) File类中有获得给定目录的上级目录名的方法吗?
- 关于Swing中的KeyListener的问题?困扰了我好久了!
- 我是个新手,我在编译的时候,出现如下提示,我想可能是库没设对吧,我用的是jdk131,请问该如何解决
- 哪儿可以找到java类库的帮助文件。类似于msdn那种
- 请教一个关于applet调用新窗口的问题/
- 谈谈面向对象
- 命令行中运行.class文件提示找不到或者无法加载主类
StringBuilder 和 StringBuffer 都是直接继续自 Object,跟那什么抽象类没关系
StringBuilder 和 StringBuffer 都是直接继续自 Object,跟那什么抽象类没关系
自己去源码。
StringBuilder 和 StringBuffer 都是直接继续自 Object,跟那什么抽象类没关系晕死JDK 的文档里说,StringBuilder 和 StringBuffer 都是直接继承自 Object,但打开这两个类的源代码,则都是继承自 AbstractStringBuilder。
当然,可能这个AbstractStringBuilder 不是公共类,所以没有出现在API 文档里
* 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);
}
} ……}
public final class StringBuilder
extends AbstractStringBuilder
implements java.io.Serializable, CharSequenceObject 是所有类的父类。