Okey, we all know the normal way to throw a IllegalArgumentException in Java:
throw new IllegalArgumentException(); // 37 characters
But there must be a shorter (as in less characters) ways to do so. How can we produce a java.lang.IllegalArgumentException with even less code?
- The code fragment has to compile and run in java 7.
- No imports/external packages (e.g. not using
java.util.Arrays.toString()
)- only exception: java.lang because it is automatically imported.
- You can add own methods/classes.
- It must throw a java.lang.IllegalArgumentException
- Edit: the error output (stacktrace) must name it java.lang.IllegalArgumentException, so no subclasses of it.
To have a base to start from:
class Titled {
public static void main(String[] args) {
throw new IllegalArgumentException();
}
}