I can't get return in function's aaa
parameters a
and b
like:
public static void aaa( boolean a , Integer b)
{
a=true;
b =2;
}
public static void main(String[] args)
{
boolean a=false;
int b=1;
aaa(a,b);
lg.info("{} {}",a,b );
}
I will get same false 1
in output.
Each time when I need to have more than one return in function I must create class-holder:
public static class BoolAndIntHolder
{
boolean a ;
Integer b ;
}
public static void aa(BoolAndIntHolder s)
{
s.a =true;
s.b =2;
}
public static void main(String[] args)
{
BoolAndIntHolder s= new BoolAndIntHolder();
s.a = false;
s.b=1;
aa(s);
lg.info("{} {}",s.a,s.b );
}
This gives true 2
in output as wanted.
But this looks so horrible each time to create different class holders. Is here any hacks how to write code in such situation in less dramatic way?
UPD
Looks like I must use data class'es in order to return several values since it is less complicated way. Solution bellow looks ugly for me. Is it possible to solve task in more elegant way?
enum TRUE_FALSE_ERR {TRUE,FALSE,ERR};
static TRUE_FALSE_ERR aaa()
{
if (isConnected())
{
if getResult() return TRUE_FALSE_ERR.TRUE else
return TRUE_FALSE_ERR.FALSE;
} else
return TRUE_FALSE_ERR.ERR;
}
public static void main(String[] args)
{
switch (aaa()) {
case ERR:
lg.info("ERR");
break;
case TRUE:
lg.info("TRUE");
break;
case FALSE:
lg.info("FALSE");
break;
default : lg.info("default");
}
}