Can you actually create a covariant sealed interface in Java? I'm trying to create a tagged union using sealed interfaces and records. I can't figure out how to keep the type in a function signature that would return it though
example
public sealed interface RepoResult<T> permits RepoResult.NotFound, RepoResult.Success {
record Success<T>(T value) implements RepoResult<T> {}
record NotFound(String message) implements RepoResult<Void> {}
}
This is invariant so I can't return NotFound for any function declared to return RepoResult<T> e.g RepoResult<Long>. Is this possible. My initial thinking is that it's not possible because Java only has use site variance, but I'm a java noob so...