Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Unchecked<T extends Exception> {
- @SuppressWarnings("unchecked")
- public static void uncheckedThrow(Exception exception) {
- Unchecked<RuntimeException> asUnchecked = new Unchecked<RuntimeException>();
- Unchecked raw = asUnchecked;
- raw.t = exception;
- asUnchecked.throwIt();
- }
- private T t;
- public void throwIt() throws T {
- throw t;
- }
- public static void main(String[] args) {
- Exception checked = new Exception();
- uncheckedThrow(checked);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement