Skip to content

Instantly share code, notes, and snippets.

@tonivade
Created June 16, 2024 07:22
Show Gist options
  • Save tonivade/bd898a05c6a87b72af4abe43fa8b934e to your computer and use it in GitHub Desktop.
Save tonivade/bd898a05c6a87b72af4abe43fa8b934e to your computer and use it in GitHub Desktop.
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