Title / Description
Code package groyve def func = { switch(it){ case Integer : return it.doubleValue() case Double : return it.intValue() case String : return it.split(" ") case null : return null default : throw new UnsupportedOperationException() } } assert func(new Integer(6)) == 6.0 assert func(new Double(Math.PI)) == 3 assert func("this is a string") == ['this', 'is', 'a', 'string'] assert func(null) == null try{ println func(new Float(5.5)) }catch(Exception ex){ assert ex.class == UnsupportedOperationException.class }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code