Valid way to format a long method call in Java

Good writing style:

objectName.methodWithManyParameters(someLongParameter1, someLongParameter2, someLongParameter3, someLongParameter4, someLongParameter5);

(which, obviously, is far from short for one line) as

objectName.methodWithManyParameters
(
    someLongParameter1, 
    someLongParameter2, 
    someLongParameter3, 
    someLongParameter4, 
    someLongParameter5
);

Another way:

objectName.methodWithManyParameters(someLongParameter1, someLongParameter2, 
                                    someLongParameter3, someLongParameter4,
                                    someLongParameter5);
+4
source share
3 answers

If you work with others or in an existing code base, use any standards that they have already used. 80 vs 100, option No. 1/2/3, etc.

If you work on your own, Jordi answers that. Use the Oracle conventions and probably jump to a string length of 100 characters; we have modern screens that fit into much, much more text than in 1996.

+3
source

In accordance with Oracle conventions :

4.2 Packing lines

, :

  • .
  • .
  • .
  • .

, , 8 .

:

someMethod(longExpression1, longExpression2, longExpression3, 
        longExpression4, longExpression5);



- , -, , - ...

+4

, . , . , Google Java. , .

(, ):

objectName.methodWithManyParameters( someLongParameter1, 
                                    someLongParameter2, 
                                    someLongParameter3, 
                                    someLongParameter4, 
                                    someLongParameter5 );

4.4 : 80 100

80 100 . , , , , 4.5, Line-.

:

, (, URL- Javadoc JSNI). import (. 3.2. 3.3 ). , . 4.5

. , , , , .

, , , . .

. .

4.5.1

: . :

, . ( , , Google , ++ JavaScript.) "" : (.), (), catch (catch (FooException | BarException e)). , , . "--" ( "foreach" ). ((), . (,) , .

+2

All Articles