I am wanting to call methods from an object from a switch statement.
Here, I am switching on a String
:
switch (properties.getProperty("my.property")) { // getProperty() retuns a String
case contains("something"):
doSomething();
break;
}
Can I execute methods of the switch
'ed object like this? Basically I'm trying to avoid doing:
case properties.getProperty("my.property").contains("something"):
I'm pretty sure it's a lost cause, but perhaps I've missed something...
I've tried using contains()
and .contains()
to no avail. Should I just stop trying to be lazy? Or is there a way to do this?
No, you can't. switch
/case
statements are for simple "this constant value maps to this set of actions; this constant value maps to this set of actions; ...".
If you need more complex processing, you should just use if
statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With