I have to use a value, typically return via a method in switch case.
int getVal(){return 121;}
switch(expr){
case getVal():
}
But its giving comilation error: constant expression required.
I also tried like,
int _val = getVal();
switch(expr){
case _val:
}
Having same result.
Is there any workaround to implement it.
Thanks,
Amit
As the error clearly states,
switchonly works with constant expressions.You need to use an
if.