Community
Participate
Working Groups
The following method produces a warning and it is fine: def boolean foo(Object value) { switch value { String: true } } But a similar method with inferred boolean type does not produce a warning: def foo(Object value) { switch value { String: true } } A method with explicit declared boolean type, but with Boolean inferred type for switch expression does not produce a warning also: def boolean foo(Object value) { switch value { case String: Boolean.TRUE } } though the generated Java code can throw a NPE: public boolean foo(final Object value) { Boolean _switchResult = null; boolean _matched = false; if (!_matched) { if (value instanceof String) { _matched=true; _switchResult = Boolean.TRUE; } } return (_switchResult).booleanValue(); // NullPointerException if a value is not of String type }