以下の2つの方法で、どちらの方法を優先する必要があります。if-else
個人的には、方法 2 のラダー 1に満足しています。しかし、私の友人は、それらはコーディングの冗長性を引き起こし、if
..のような多くの単一のステートメントでそれを達成していたと言いました.. 例:
if( cond1 && cond2 ){}
if(cond1 && cond3){}
if(cond3 && cond2){} etc..
Instead of.,
if(cond1)
{
}
else
{
if(cond3 && cond2)
{}
}
//Way 1
String str = cond1 && !cond2 && !cond3 ? "world" : "hello" ;
(cond1,cond2,cond3 -> aren't simple checks. say they itself contains many || and &&'s )
//Way 2
String str;
if (cond1)
{
if (cond2)
{
str = "hello";
}
else
{
if (cond3)
{
str = "hello";
}
else
{
str = "world";
}
}
}