Skip to content

Instantly share code, notes, and snippets.

@nothub
Last active August 13, 2020 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nothub/cadd93c4b40a90955e6fe306e9c05730 to your computer and use it in GitHub Desktop.
Save nothub/cadd93c4b40a90955e6fe306e9c05730 to your computer and use it in GitHub Desktop.
package not.hub.test;
class UnsoundTypeBreakage<T, U> {
final Constrain<? super T> constrain;
final U u;
UnsoundTypeBreakage(T t) {
u = coerce(t);
constrain = getConstrain();
}
public static void main(String[] args) {
String zero = new UnsoundTypeBreakage<Integer, String>(0).u;
}
<B extends U>
U upcast(Constrain<B> constrain, B b) {
return b;
}
U coerce(T t) {
return upcast(constrain, t);
}
Constrain<? super T> getConstrain() {
return constrain;
}
class Constrain<B extends U> {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment