JDK 16 RFR of JDK-8248983: Add Name.isEmpty

Jonathan Gibbons jonathan.gibbons at oracle.com
Thu Jul 9 00:05:08 UTC 2020

On 7/8/20 3:31 PM, forax at univ-mlv.fr wrote:
> ----- Mail original -----
>> De: "joe darcy" <joe.darcy at oracle.com>
>> À: "Remi Forax" <forax at univ-mlv.fr>
>> Cc: "compiler-dev" <compiler-dev at openjdk.java.net>
>> Envoyé: Mercredi 8 Juillet 2020 18:23:21
>> Objet: Re: JDK 16 RFR of JDK-8248983: Add Name.isEmpty
>> Hi Remi,
>> The value of the method is to provide a reference point within the
>> javax.lang.model API for the "empty name" concept. The goal for the code
>> in the body of Name.isEmpty is to have as little as possible, preferably
>> just delegating to CharSequence.isEmpty. I'd prefer to have the empty
>> name links point to the method Name.isEmpty rather than
>> CharSequence.isEmpty, hence defining a minimal Name.isEmpty method
>> within the API.
> I can buy that the concept of empty name is important, following what you are saying, length() should be re-abstracted for the exact same reason.
> I think i prefer to follow the current implementation of Name that explain the concept of empty name in the top level javadoc of Name, and fix the sentence "An empty Name has a length of zero." to mention isEmpty.

The concept of 'empty name' could be explained in the class comment for 
Name, as Rémi suggests, and enclosed or prefixed by some HTML that 
defines an 'id' such as "empty-name" that can be referenced from other 
locations, without having to introduce a new method for the concept. 
(But, for me, I'm OK either way.)

-- Jon

>> HTH,
>> -Joe
> Rémi
>> On 7/8/2020 5:15 AM, Remi Forax wrote:
>>> HI Joe,
>>> I don't understand the value that this method provides,
>>> because either the JDK 15 is the bootstrap JDK and in this case, this code is
>>> useless because CharSequence.isEmpty() already provides the right behavior,
>>> or you don't and it will not compile.
>>> So either you write it to delegate to length() so you are not dependent of JDK
>>> 15 being the bootstrap JDK or you do nothing and you will get isEmpty() for
>>> free when the JDK 15 will be the bootstrap JDK.
>>> public interface Name extends CharSequence {
>>>        /**
>>> +     * Returns {@code true} if this is an empty name with a length of
>>> +     * zero; returns {@code false} otherwise.
>>> +     * @return {@code true} for an empty name and {@code false} otherwise.
>>> +     *
>>> +     * @since 16
>>> +     */
>>> +    default boolean isEmpty() {
>>> +        return length() == 0;
>>> +    }
>>> regards,
>>> Rémi
>>> ----- Mail original -----
>>>> De: "joe darcy" <joe.darcy at oracle.com>
>>>> À: "compiler-dev" <compiler-dev at openjdk.java.net>
>>>> Envoyé: Mercredi 8 Juillet 2020 04:23:32
>>>> Objet: JDK 16 RFR of JDK-8248983: Add Name.isEmpty
>>>> Hello,
>>>> Please review the webev and CSR for
>>>>       JDK-8248983: Add Name.isEmpty
>>>>       CSR: https://bugs.openjdk.java.net/browse/JDK-8249005
>>>>       webrev: http://cr.openjdk.java.net/~darcy/8248983.0/
>>>> In its current form, this fix can only be pushed *after* the minimum
>>>> boot JDK in the JDK 16 build is updated to JDK 15. Otherwise, the
>>>> default method on CharSequence is not necessarily present.
>>>> To be pushed earlier, the default method on Name would need to be
>>>> changed to host an implementation that didn't delegate to
>>>> CharSequence.isEmpty. It would not be difficult to take that route
>>>> instead with a follow-up bug to change the implementation of the default
>>>> method later.
>>>> Thanks,
>>>> -Joe

More information about the compiler-dev mailing list