You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Marcin Zajaczkowski (Jira)" <ji...@apache.org> on 2020/03/15 17:08:00 UTC
[jira] [Updated] (GROOVY-9470) Automatic type casting with
switch..case with instanceof
[ https://issues.apache.org/jira/browse/GROOVY-9470?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Marcin Zajaczkowski updated GROOVY-9470:
----------------------------------------
Summary: Automatic type casting with switch..case with instanceof (was: Automatic type casting with switch..case with instanceOf)
> Automatic type casting with switch..case with instanceof
> --------------------------------------------------------
>
> Key: GROOVY-9470
> URL: https://issues.apache.org/jira/browse/GROOVY-9470
> Project: Groovy
> Issue Type: Improvement
> Components: Compiler
> Affects Versions: 3.0.2
> Reporter: Marcin Zajaczkowski
> Priority: Minor
>
> It could be useful to have automatic type casting (also with static compilation) with switch..case with instanceof:
> {code:java}
> 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())
> }
> }
> {code}
> The same as currently for if with instanceof:
> {code:java}
> if (o instanceof String) {
> useString(o)
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)