Hello! Consider the following code:
public class A { private String str; public void f(Object obj) { if (obj instanceof String str) { System.out.println(str.toLowerCase()); // str refers to pattern binding } else { System.out.println(str.toLowerCase()); // str refers to the field } } } I thought that such a code should be rejected by the compiler, as it's confusing and could be a source of very subtle bugs. However, I haven't found any explicit statement regarding this in the latest spec draft [1]. Could you please clarify whether such code is acceptable and point me to the relevant part of the spec draft. Thank you! With best regards, Tagir Valeev. [1] http://cr.openjdk.java.net/~gbierman/jep305/jep305-20191021/specs/patterns-instanceof-jls.html