• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Sybex CSG 17: page 221 / table 5.1 potential error with "method signature"

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

I'd like to report a potential error on page 221 in table 5.1. The table mentions that the method signature is

but I think it's more correct to say it is

The parameter name isn't part of the method signature.
 
Sheriff
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is understandable what you are saying. Yes and No. But I believe author(s) of the book mention what is part of the signature. It just not conventional to show some non-valid Java code and say it is a signature.

I think they mean along the lines: "Here you see two valid methods, that share the same signature...".

Even JLS (Java Language Specification) talks about method signature by demonstrating the use of two valid methods that clash in signature.
Ref: https://docs.oracle.com/javase/specs/jls/se21/html/jls-8.html#jls-8.4.2
 
Marshal
Posts: 80223
424
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the pedantic thing to say is that OP is correct.

$ jshell
|  Welcome to JShell -- Version 20.0.2
|  For an introduction type: /help intro
c
jshell> class Foo
  ...> {
  ...>     public void foo(int i)
  ...>     {
  ...>         System.out.println(i);
  ...>     }
  ...>    
  ...>     private int foo (int number)
  ...>     {
  ...>         return number >> 1;
  ...>     }
  ...> }
|  Error:
|  method foo(int) is already defined in class Foo
|      private int foo (int number)
|      ^---------------------------...

jshell>

The two methods have the same signatures, and the JShell tool correctly refused to compile such crappy code
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy Patrick, welcome to coderanch.

I guess the authors didn't want to confuse people by removing the parameter name. Other than that you are right, the parameter name is not part of the method signature. So if two methods have same name and parameter types, then the parameter names don't matter and both methods have same signature.
 
Campbell Ritchie
Marshal
Posts: 80223
424
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:Howdy Patrick, welcome to coderanch. . . .

Howdy ,Ankit. Good to see  you back here.
 
straws are for suckers. tiny ads are for attractive people.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic