Created
June 16, 2024 07:22
-
-
Save tonivade/bd898a05c6a87b72af4abe43fa8b934e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| sealed interface Data<T> { | |
| record DataString(String value) implements Data<String> {} | |
| static <T> T get(Data<T> data) { | |
| // why I need to force the cast to T? | |
| return (T) switch (data) { | |
| case DataString(var value) -> value; | |
| }; | |
| } | |
| } | |
| var value = new Data.DataString("Hello"); | |
| System.out.println(Data.get(value)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment