Formatting multiple arguments passed to a function in Java

后端 未结 6 1021
广开言路
广开言路 2021-02-13 21:18

Often the number of arguments passed to a function can be large. Consider the following case:

calculate(dataManager.getLastUpdate().getNumberOfChildren(),
               


        
6条回答
  •  无人共我
    2021-02-13 21:35

    When I have to call a method like this I like to put the arguments on their own line, like so:

    final int result = calculate (
        dataManager.getLastUpdate().getNumberOfChildren(),
        dataManager.getLastUpdate().getNumberOfParents(),
        dataManager.getLastUpdate().getNumberOfGrandChildren(),
        milliseconds,
        somethingelse
    );
    

    Obviously this is a personal preference, but if you're working with others on code, try to conform to the conventions already set forth.

提交回复
热议问题