[patterns] reconsidering how the created variable name binds

Remi Forax forax at univ-mlv.fr
Wed Jan 1 18:22:30 UTC 2020


In this peculiar code, we can still 

----- Mail original -----
> De: "John Rose" <john.r.rose at oracle.com>
> À: "Reinier Zwitserloot" <reinier at zwitserloot.com>
> Cc: "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Samedi 28 Décembre 2019 21:47:12
> Objet: Re: [patterns] reconsidering how the created variable name binds

>> On Dec 28, 2019, at 9:52 AM, Reinier Zwitserloot <reinier at zwitserloot.com>
>> wrote:
>> 
>>   static /*?final?*/ boolean FLAG = true;
>>   static String v = "field";
>>   public void test() {
>>       String obj = "Pattern match";
>>       if (!(obj instanceof String v)) {
>>           // This branch is never taken.
>>           while (FLAG) ; // endless
>>       }
>> 
>>       System.out.println(v);
> 
> Yes, DU and static final are both examples of action at a distance and they can
> be combined. Add inheritance of the final for an extra-good time. Such puzzlers
> do not usually drive the design of the language, as you surmise later on; at
> some point (including here IMO) we can agree to say, “yeah, but that’s an
> academic point”.

[...]

hum, i think i prefer to have this code to not compile

  public static void test() {
    String obj = ...
    if (!(obj instanceof String s)) {
      // i forgot to die here !
    }
  }

instead of having s to be not defined.


> 
> – John

Rémi


More information about the amber-dev mailing list