8215401: Add isEmpty default method to CharSequence

Reviewed-by: jlaskey, rriggs, jjg, alanb, smarks, darcy
This commit is contained in:
Claes Redestad 2020-05-22 11:20:57 +02:00
parent 7d330d34f1
commit 113c48f5da
4 changed files with 133 additions and 1 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -87,6 +87,21 @@ public interface CharSequence {
*/
char charAt(int index);
/**
* Returns {@code true} if this character sequence is empty.
*
* @implSpec
* The default implementation returns the result of calling {@code length() == 0}.
*
* @return {@code true} if {@link #length()} is {@code 0}, otherwise
* {@code false}
*
* @since 15
*/
default boolean isEmpty() {
return this.length() == 0;
}
/**
* Returns a {@code CharSequence} that is a subsequence of this sequence.
* The subsequence starts with the {@code char} value at the specified index and

View file

@ -684,6 +684,7 @@ public final class String
*
* @since 1.6
*/
@Override
public boolean isEmpty() {
return value.length == 0;
}