Skip to content

Instantly share code, notes, and snippets.

@opqdonut
Created January 25, 2017 11:46
Show Gist options
  • Select an option

  • Save opqdonut/5082314d0bd077fb1b2175e1f6cdb3f2 to your computer and use it in GitHub Desktop.

Select an option

Save opqdonut/5082314d0bd077fb1b2175e1f6cdb3f2 to your computer and use it in GitHub Desktop.
class Unsound {
static class Constrain<A, B extends A> {}
static class Bind<A> {
<B extends A> A upcast(Constrain<A,B> constrain, B b) {
return b;
}
}
static <T,U> U coerce(T t) {
Constrain<U, ? super T> constrain = null;
Bind<U> bind = new Bind<U>();
return bind.upcast(constrain, t);
}
public static void main(String[] args) {
String zero = Unsound.<Integer,String>coerce(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment