conditional - java using logical operators instead of if-else if for return -



conditional - java using logical operators instead of if-else if for return -

i have next code in equals method.

public boolean equals(object o){ if (o == null) homecoming false; if (o == this) homecoming true; if (!(o instanceof vertex)) homecoming false; homecoming ((vertex) o).label().equals(label); }

my ide highlights if statement , wants me this

public boolean equals(object o){ homecoming (o != null) && ((o==this) || ((o instanceof vertex) && ((vertex) o).label().equals(label); }

i've been told compiler smart plenty optimize , in general 1 should code readability. so, sec code sample not easy read first. ide beingness annoying or there actual performance merit doing way?

first, optimize if know it's bottleneck, else code readability.

you can check byte code see suspect pretty close if not same. if there slight differences in bytecode, i've seen jit compiler optimize stuff downwards there no difference. can performance tests sure.

java conditional return logical-operators

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -