> On Jan 10, 2020, at 4:00 PM, John Rose <[email protected]> wrote:
> 
> On Jan 10, 2020, at 12:00 PM, Brian Goetz <[email protected]> wrote:
>> . . .
> 
>> We might want to go a little further, and ban constant patterns in 
>> instanceof too, since all of the following have simpler forms:
>> 
>>    if (x instanceof null) { ... }
>>    if (x instanceof "") { ... }
>>    if (i instanceof 3) { ... }
>> 
>> Or not -- I suspect not.
> 
> One reason to keep it is floats:
> 
>  if (x instanceof Float.NaN) { … }
> 
> This seems to be a fine thing for an IDE to warn about, and not
> so fine for a language to legislate.

Well, if the _only_reason to allow instanceof with a constant is floats and 
doubles (comparing to NaN is the one thing that == or .equals might not handle 
properly), then it’s not a very good reason; I dare say Float.isNan(x) is the 
first thing that would jump to mind, and it would be a whole lot more readable 
as well.

—Guy

Reply via email to