-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[jdk22] Adds support for unnamed variables (JEP 456)
- Loading branch information
Showing
3 changed files
with
151 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// version 22: | ||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
import java.util.stream.Stream; | ||
|
||
record Box<T>(T content) { | ||
} | ||
|
||
record Pair<T, U>(T first, U second) { | ||
} | ||
|
||
public class UnnamedVariables { | ||
void enhancedLoop() { | ||
for (String _ : Arrays.asList("")) { | ||
} | ||
} | ||
|
||
void initializationInForLoop() { | ||
for (int i = 0, _ = Integer.MAX_VALUE; i < 10; i++) { | ||
} | ||
} | ||
|
||
void assignment() { | ||
var _ = 1; | ||
} | ||
|
||
void catchBlock() { | ||
try { | ||
} catch (Exception _) { | ||
} | ||
} | ||
|
||
void tryWithResources() { | ||
try (var _ = new Scanner("")) { | ||
} | ||
} | ||
|
||
void lambda() { | ||
Stream.of(1).forEach(_ -> { | ||
}); | ||
} | ||
|
||
Object switchStatement(Object o) { | ||
return switch (o) { | ||
case String _, Integer _ -> o; | ||
case Long _ -> o; | ||
default -> o; | ||
}; | ||
} | ||
|
||
void recordPattern(Object o) { | ||
if (o instanceof Pair(Box _, Box(Integer _))) { | ||
} | ||
if (o instanceof Box(String _)) { | ||
} | ||
if (o instanceof Box(var _)) { | ||
} | ||
if (o instanceof Box(_)) { | ||
} | ||
} | ||
|
||
Object recordPatternSwitch(Object o) { | ||
return switch (o) { | ||
case Box(String _), Box(Integer _) -> o; | ||
case Box(Long _) -> o; | ||
case Box(_) -> o; | ||
default -> o; | ||
}; | ||
} | ||
} |
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,70 @@ | ||
// version 22: | ||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
import java.util.stream.Stream; | ||
|
||
record Box<T>(T content) { | ||
} | ||
|
||
record Pair<T, U>(T first, U second) { | ||
} | ||
|
||
public class UnnamedVariables { | ||
void enhancedLoop() { | ||
for (String _ : Arrays.asList("")) { | ||
} | ||
} | ||
|
||
void initializationInForLoop() { | ||
for (int i = 0, _ = Integer.MAX_VALUE; i < 10; i++) { | ||
} | ||
} | ||
|
||
void assignment() { | ||
var _ = 1; | ||
} | ||
|
||
void catchBlock() { | ||
try { | ||
} catch (Exception _) { | ||
} | ||
} | ||
|
||
void tryWithResources() { | ||
try (var _ = new Scanner("")) { | ||
} | ||
} | ||
|
||
void lambda() { | ||
Stream.of(1).forEach(_ -> { | ||
}); | ||
} | ||
|
||
Object switchStatement(Object o) { | ||
return switch (o) { | ||
case String _, Integer _ -> o; | ||
case Long _ -> o; | ||
default -> o; | ||
}; | ||
} | ||
|
||
void recordPattern(Object o) { | ||
if (o instanceof Pair(Box _, Box(Integer _))) { | ||
} | ||
if (o instanceof Box(String _)) { | ||
} | ||
if (o instanceof Box(var _)) { | ||
} | ||
if (o instanceof Box(_)) { | ||
} | ||
} | ||
|
||
Object recordPatternSwitch(Object o) { | ||
return switch (o) { | ||
case Box(String _), Box(Integer _) -> o; | ||
case Box(Long _) -> o; | ||
case Box(_) -> o; | ||
default -> o; | ||
}; | ||
} | ||
} |