• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is This Considered a Different Parameter List?  RSS feed

 
Russ Russell
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is merely changing x to final in the go() method enough to consider this a different parameter list, and therefore an overloaded version of the method? Or is it the same parameter list and therefore an overridden version of the method?

If I limit the access of the method in Hello2 (by making it default), the compiler complains that I can't do that when overriding, so the compiler must consider final int x the same parameter list. I suppose this answers the question, but I just want to verify this with others.

Thank you,
-Russ

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Russ Russell wrote:Is merely changing x to final in the go() method enough to consider this a different parameter list, and therefore an overloaded version of the method?


Nope. Parameter lists are distinguished only by the types of their args and the order in which those args appear.
 
Russ Russell
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you , Jeff.

Swapping the order of the parameters in the list is considerend a different signature?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you have already answered your own question, so there's not much more to say. Perhaps only that only the types and order of the parameter list is considered. Names, annotations and modifiers (like final) are not.

Edit: in answer to your second question, only if the types of the variables are different is it considered a different signature. Swapping two int parameters will not change a thing.
 
Russ Russell
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both. Crystal clear.

-Russ
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!