lundi 10 juillet 2017

Why are single statement conditions in java expresesd using blocks?

Suppose I have the following code:

public class Test{
    public static void main(String arguments[]){
        if(true){
            System.out.println("Hello, world!");
        }
    }
}

It would be more efficient to do this:

public class Test{
    public static void main(String arguments[]){
        if(true) System.out.println("Hello, world!");
    }
}

Is there any reason the first method is much more commonly used besides convention?

Aucun commentaire:

Enregistrer un commentaire