thomas.behr wrote:... Now I feel really stupid.gimbal2 wrote:AbstractStringBuilder is (and always has been) package-private. The regular API documentation only lists public classes.
Its not there nor has it ever been there. What the hey?
user9106296 wrote:When evaluating the
see the below thread for StringBuffer using AbstractStringBuilder in its implementation
StringBuilder API question
Finally narrowed down this to a line of code, where a ternary operation is done.
System.out.println( sb == null ? new StringBuilder() : sb); here sb is an instance of StringBuffer.
Any thoughts on why this happens ?
expression, the compiler needs to determine the type of the resulting value. Moreover, the determined type must be a supertype of both, the operator's second and third operand. Since StringBuffer is not a StringBuilder, it cannot be StringBuilder. So a widening conversion happens. The second operand's superclass is AbstractStringBuilder and as it happens that is the superclass of the third operand, too.
sb == null ? new StringBuilder() : sb