Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing arguments in multiple lines

 
Nich Aquilina
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is there any way to split code in more than one line? to avoid scrolling? This especiallyin constructor, for example:-

Worker(String name, String firstName, String dateOfBirth, String........)

Thanks
Nich
 
John Bartlett
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not entirely sure what you mean by this, but if you mean just to avoid horizontal scrolling then why not just put the next param on a new line?

e.g.



although if you mean knowing that you are going to be receiving multiple params of the same type, i.e. above, and you want to reduce the code, then couldnt you use a varargs e.g.



Not sure if that is what you wanted but hope it helps,

John
[ February 06, 2007: Message edited by: John Bartlett ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doesn't distinguish between new lines and other white space (outside of comments and String literals). That is, everywhere you can use a space character, you can also use a new line. Both of the following code snippets are totally valid Java code:





Both aren't styles I would recommend, though...
 
Nich Aquilina
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, that was it. Not the extreme one but worked great.

ManualWorker(String familyName,
String firstName,
String dateOfBirth,
String employeeNumber,
String dateOfFirstEmployment,
 
Nich Aquilina
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, that was it. worked great.

ManualWorker(String familyName,
String firstName, String dateOfBirth, String employeeNumber,
String dateOfFirstEmployment)

Nicholas
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic