nurkiewicz / typeof

instanceof operator and Visitor pattern replacement in Java 8

Home Page:http://nurkiewicz.blogspot.com/2013/09/instanceof-operator-and-visitor-pattern.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add orElseThrow

udalrich opened this issue · comments

It would be good to be able to do something like

int len = 
 whenTypeOf(x).
   is(String.class).
   thenReturn(s -> s.length()).
   is(Collection.class).
   thenReturn(c -> c.size()).
   orElseThrow(o -> new RuntimeException("My custom message about"+ o));

so that, if the input object is not a type that I handle, I can generate the exception that I want.