On Fri, 5 Mar 2021 17:03:34 GMT, Claes Redestad <redes...@openjdk.org> wrote:

>> src/java.base/share/classes/java/util/Formatter.java line 3017:
>> 
>>> 3015:                 s = ((Character)arg).toString();
>>> 3016:             } else if (arg instanceof Byte) {
>>> 3017:                 byte i = (Byte) arg;
>> 
>> Can the pattern matching for instanceof be used here to remove explicit 
>> casts.  (Supported in JDK 16) 
>>  s = null;
>>             if (arg instanceof Character c) {
>>                 s = c.toString();
>>             } else if (arg instanceof Byte i) {
>>                 if (Character.isValidCodePoint(i))
>>                     s = new String(Character.toChars(i));
>>                 else
>>                     throw new IllegalFormatCodePointException(i);
>>             } else if (arg instanceof Short i) {
>>                 if (Character.isValidCodePoint(i))
>>                     s = new String(Character.toChars(i));
>>                 else
>>                     throw new IllegalFormatCodePointException(i);
>>             } ```
>> etc..
>
> I did think about it, but it seemed to stray a bit too far from the intent of 
> this enhancement.

I only looked at it because of the updates to use switch expressions...
ok, either way.

-------------

PR: https://git.openjdk.java.net/jdk/pull/2830

Reply via email to