Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Duplicate
-
3.0.2
-
None
-
None
Description
It could be useful to have automatic type casting (also with static compilation) with switch..case with instanceof:
void sortItOut(Object o) { switch(o) { case String: println "String: ${o.length()}" //currently only in dynamic Groovy break case Integer: println "Integer: ${o.longValue()}" //currently only in dynamic Groovy break default: throw new IllegalArgumentException(o.toString()) } }
The same as currently for if with instanceof:
if (o instanceof String) { useString(o) }
Attachments
Issue Links
- duplicates
-
GROOVY-8411 Support instanceof-like flow typing for class literal switch case
-
- Closed
-