TODO: Add cheesey type refinement (sketched in the phantom types thread as well)
Checked exceptions as unchecked
Java the language requires checked exceptions, where the JVM does not. This uses type erasure to allow throwing a checked exception as unchecked.
public final class Util {
/** For erasing the type of the checked exception */
@SuppressWarnings("unchecked")
private static <E extends Throwable> void throw_(Throwable e) throws E
{
throw (E)e;
}
/** Throws a checked exception 't' as unchecked. */
public static void silentThrow(Throwable t)
{
Util.<RuntimeException>throw_(t);
}
}
Constructor hugger
public class Animal<T>
{
public <P> Animal(P mommy, P daddy) {
...
}
}
dog = new <Wolf>Animal<Dog>(wooo, woooo);