Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3251 from Rawi01/jdk19
Add support for JDK 19
- Loading branch information
Showing
8 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
record Point(int x, int y) { | ||
} | ||
record Rectangle(Point upperLeft, Point lowerRight) { | ||
} | ||
|
||
public class RecordPattern { | ||
void recordPattern(Object o) { | ||
if (o instanceof Point(int x, int y)) { | ||
} | ||
if (o instanceof Point(int x, int y) p) { | ||
} | ||
if (o instanceof Rectangle(Point(int x1, int y1), Point(int x2, int y2))) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
public class Switch19 { | ||
String switchPatternMatching(Object o) { | ||
return switch (o) { | ||
case Integer i -> String.format("int %d", i); | ||
case Long l -> String.format("long %d", l); | ||
case Double d -> String.format("double %f", d); | ||
case String s -> String.format("String %s", s); | ||
default -> o.toString(); | ||
}; | ||
} | ||
|
||
String switchNull(Object o) { | ||
return switch (o) { | ||
case null, default -> "?"; | ||
}; | ||
} | ||
|
||
String switchGuardPattern(Object o) { | ||
return switch (o) { | ||
case String s when s.length() > 1 -> s; | ||
case String s -> s; | ||
default -> o.toString(); | ||
}; | ||
} | ||
|
||
String switchParenthesizedPattern(Object o) { | ||
return switch (o) { | ||
case (String s) -> s; | ||
default -> o.toString(); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// version 19: | ||
record Point(int x, int y) { | ||
} | ||
record Rectangle(Point upperLeft, Point lowerRight) { | ||
} | ||
|
||
public class RecordPattern { | ||
void recordPattern(Object o) { | ||
if (o instanceof Point(int x, int y)) { | ||
} | ||
if (o instanceof Point(int x, int y) p) { | ||
} | ||
if (o instanceof Rectangle(Point(int x1, int y1), Point(int x2, int y2))) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// version 19: | ||
public class Switch19 { | ||
String switchPatternMatching(Object o) { | ||
return switch (o) { | ||
case Integer i -> String.format("int %d", i); | ||
case Long l -> String.format("long %d", l); | ||
case Double d -> String.format("double %f", d); | ||
case String s -> String.format("String %s", s); | ||
default -> o.toString(); | ||
}; | ||
} | ||
|
||
String switchNull(Object o) { | ||
return switch (o) { | ||
case null, default -> "?"; | ||
}; | ||
} | ||
|
||
String switchGuardPattern(Object o) { | ||
return switch (o) { | ||
case String s when s.length() > 1 -> s; | ||
case String s -> s; | ||
default -> o.toString(); | ||
}; | ||
} | ||
|
||
String switchParenthesizedPattern(Object o) { | ||
return switch (o) { | ||
case (String s) -> s; | ||
default -> o.toString(); | ||
}; | ||
} | ||
} |