jslvtr jslvtr - 3 months ago 5
Java Question

Assign variable value inside if-statement

I was wondering whether it is possible to assign a variable a value inside a conditional operator like so:

if((int v = someMethod()) != 0) return v;

Is there some way to do this in Java? Because I know it's possible in
conditions, but I'm not sure if I'm doing it wrong for the if-statement or if it's just not possible.


do something like

int v;
if((v = someMethod()) != 0) return true;