The Unsound Playground

Fork me on GitHub
Artifact Award

We, Nada Amin and Ross Tate, broke the Java and Scala type systems!
Try it out for yourself by running the examples, which throw cast exceptions even though they contain no casts ↓
Read our paper Java and Scala's Type Systems are Unsound to learn how these examples work →
Come up with your own examples and use the save icon to update the URL to a permalink to your code ↱

Which language would you like to break?
Java / Scala

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); } }
#!/bin/bash set -e -v ### PICK VERSION export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH ### CHECK VERSION java -version ### COMPILE cat $1 > javac ### RUN java Unsound