I am working in Java 19, and using the pattern matching for instanceof that was released in JEP 394 (which released in Java 16). However, I am running into a warning that I am struggling to understand.
public class ExpressionTypeIsASubsetOfPatternType
{
public record Triple(int a, int b, int c) {}
public static void main(String[] args)
{
System.out.println("Java Version = " + System.getProperty("java.version"));
final Triple input = new Triple(1, 2, 3);
if (input instanceof Triple t)
{
System.out.println("Made it here");
}
}
}
And here is the warning that is returned.
$ javac -Xlint:preview --enable-preview --release 19 UnconditionalPatternsPreviewWarning.java
UnconditionalPatternsPreviewWarning.java:15: warning: [preview] unconditional patterns in instanceof are a preview feature and may be removed in a future release.
if (input instanceof Triple t)
^
1 warning
What does this warning message mean? More specifically, what does an unconditional pattern mean? I tried to search on StackOverflow, but found nothing helpful or useful on this.
I understand well enough that, whatever it is, is a preview feature. And thus, I am trying to do something that has not yet been released. But this looks and sounds like the most basic possible pattern match using the most basic form of pattern-matching --- instanceof. And the JEP that I linked above made it sound like this feature is released.
I guess whatever it is I am doing is an unconditional pattern. But what does that mean?