• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Sybex CSG 17 - Varargs in method signature on page 167 (Chapter 4)

 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the bottom of page 167 (in the section Formatting Values of Chapter 4), the following method signatures are stated:

However, shouldn't "..." be after Object instead of args?
 
Saloon Keeper
Posts: 5536
213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Rik,

welcome to the Ranch!

You are right, the ellipsis should be after Object.
 
Marshal
Posts: 79716
381
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, as you and Piet both said, it is better style to have the ... as part of the type rather than the parameter name. But the compiler will accept both. If you look in the Formatter documentation, you will find the better format used. Strictly speaking, the method signature should not include parameter names.
 
Master Rancher
Posts: 5011
79
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:But the compiler will accept both.


That's not true. You may be thinking of array type declarations.  For historical (C language) reasons, Java has always accepted either

or

However, that does not extend to vararg declarations. In Java, the ... needs to be after the type, not the variable name.  So always

never

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Yes, as you and Piet both said, it is better style to have the ... as part of the type rather than the parameter name. But the compiler will accept both. If you look in the Formatter documentation, you will find the better format used. Strictly speaking, the method signature should not include parameter names.



As said in prior comment,  

But the compiler will accept both.

doesn't seem right.

 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

You are correct. I've added this to the errata and credited you.
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic