> Straight from the JLS:
>
> 8.4.3.3 final Methods
>
> A method can be declared final to prevent
> subclasses from overriding
> or hiding it. It is a compile-time error to attempt
> to override or hide a final method.
>
> Oh, it's you again ...
>
> Jos
My Goodness, let me ask in another way, detailing a bit more: why would a programmer want to hide a static method? No benefit doing it.
> My Goodness, let me ask in another way, detailing a
> bit more: why would a programmer want to hide a
> static method? No benefit doing it.
My goodness...
Hiding a static method is not a good thing.
Declaring static methods as final prevents subclasses from hiding them.
Soooo.... Declaring static methods as final prevents something that's not good.
> > My Goodness, let me ask in another way, detailing
> a
> > bit more: why would a programmer want to hide a
> > static method? No benefit doing it.
>
> My goodness...
> Hiding a static method is not a good thing.
> Declaring static methods as final prevents subclasses
> from hiding them.
> Soooo.... Declaring static methods as final prevents
> something that's not good.
My Goodness... if you "override" a static method in the subclass you have two static methods available. Sooooooooooooo... hiding a static method is a good thing sometimes, why not?
> > hiding a static method is a good thing sometimes,
> why not?
>
> Note the 'sometimes', when 'sometimes not' applies
> make your static
> methods final.
>
> Jos
In instance methods, overriding is a good thing. But in static methods, there isn磘 a good reason for not permitting hiding the method.
> > hiding a static method is a good thing sometimes,
> why not?
>
> Note the 'sometimes', when 'sometimes not' applies
> make your static
> methods final.
>
> Jos
You caught me. It seems that I am giving an argument, and at the same time the counter-argument for my argument. Let me rephrase: hiding the static method is a good thing sometimes, not hiding that static method is also a good thing sometimes. But not permitting the method be hidden is not a good thing, in any case.
> > Note the 'sometimes', when 'sometimes not' applies
> > make your static methods final.
>
> Let me rephrase: hiding the static method is a good thing
> sometimes, not hiding that static method is also a good thing
> sometimes. But not permitting the method be hidden is not a good
> thing, in any case.
Your conclusion if false because of your own reasoning: sometimes
it's good to hide static methods and sometimes it's not. Not permitting
methods to be hidden sometimes is a good thing when explicitly
applied (by using that final keyword).
Jos
> > > Note the 'sometimes', when 'sometimes not'
> applies
> > > make your static methods final.
> >
> > Let me rephrase: hiding the static method is a good
> thing
> > sometimes, not hiding that static method is also a
> good thing
> > sometimes. But not permitting the method be hidden
> is not a good
> > thing, in any case.
>
> Your conclusion if false because of your own
> reasoning: sometimes
> it's good to hide static methods and sometimes it's
> not. Not permitting
> methods to be hidden sometimes is a good thing when
> explicitly
> applied (by using that final keyword).
>
> Jos
No.
... let me try again:
You are subclassing a class. YOU decide if it is good or not hiding the super static method, not the creator of the superclass. That磗 my argument. Am I clear now?
> You are subclassing a class. YOU decide if it is good
> or not hiding the super static method, not the
> creator of the superclass. That磗 my argument. Am I
> clear now?
Nope, the creator of the superclass determines whether or not a non-
static method can be overridden by using the final keyword and so can
s/he decide whether or not a static method can be hidden by applying
that same keyword to the static method.
Jos
I asked that because I think "Gosling" defined that rule in JLS, that says "A method can be declared final to prevent subclasses from overriding
or HIDDING it." just to see if someone in the world invents a good reason for the usage of final keyword in this situation, like if you said "let me see the things happen...", but nobody invented that yet, for the sadness of "Gosling". And I doubt that there is a good reason for that.
The reply 2 (mine) is not clear, I admit. In this reply, I am citing "hide" in the wrong meaning, but I hope that now, with my other replies, my intention is clear.
> > You are subclassing a class. YOU decide if it is
> good
> > or not hiding the super static method, not the
> > creator of the superclass. That磗 my argument. Am
> I
> > clear now?
>
> Nope, the creator of the superclass determines
> whether or not a non-
> static method can be overridden by using the final
> keyword and so can
> s/he decide whether or not a static method can be
> hidden by applying
> that same keyword to the static method.
>
> Jos
What would be the destruction caused by anyone who hides the super static method? There isn磘 any destruction, nor any bad designing damage. Actually, the final keyword for static methods is the bad thing here. Everybody should avoid this keyword in this situation, for the designing goodness. Of course, considering that all the programmers are experienced, and know Java very well.
> You are subclassing a class. YOU decide if it is good
> or not hiding the super static method, not the
> creator of the superclass. That磗 my argument. Am I
> clear now?
The creator of a class decides what that class' members' visibility should be. This is the way it is and this is the way that makes the most sense.
> > You are subclassing a class. YOU decide if it is
> good
> > or not hiding the super static method, not the
> > creator of the superclass. Thats my argument. Am
> I
> > clear now?
>
> The creator of a class decides what that class'
> members' visibility should be. This is the way it is
> and this is the way that makes the most sense.
Oops. Too late to edit. Should have been "hideability", not "visibility."