static final method

Why would a programmer declare a static method as final? Speaking about class designing.
[95 byte] By [yamm_v5.0.20-alphaa] at [2007-11-26 22:50:23]
# 1
Straight from the JLS:8.4.3.3 final MethodsA 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
JosAHa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 2

> 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.

yamm_v5.0.20-alphaa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 3

> 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.

Lokoa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 4

> > 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?

yamm_v5.0.20-alphaa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 5
> hiding a static method is a good thing sometimes, why not?Note the 'sometimes', when 'sometimes not' applies make your staticmethods final.Jos
JosAHa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 6

> > 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.

yamm_v5.0.20-alphaa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 7
> in static methods, there isn磘 a good reason for not permitting hiding the method.See replies 4 and 5.There either isn't a good reason for not permitting, or there is sometimes goodreason to permit. Make up your mind which you're asserting and stick to
pbrockway2a at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 8

> > 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.

yamm_v5.0.20-alphaa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 9

> > 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

JosAHa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 10

> > > 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?

yamm_v5.0.20-alphaa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 11

> 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

JosAHa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 12

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.

yamm_v5.0.20-alphaa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 13

> > 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.

yamm_v5.0.20-alphaa at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 14

> 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.

jverda at 2007-7-10 12:11:35 > top of Java-index,Java Essentials,Java Programming...
# 15
> Actually,> the final keyword for static methods is the bad thing> here. Everybody should avoid this keyword in this> situation, for the designing goodness. You have provided zero support for that, as for every one of your so-caleld "arguments."
jverda at 2007-7-21 19:16:48 > top of Java-index,Java Essentials,Java Programming...
# 16

> > 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."

jverda at 2007-7-21 19:16:48 > top of Java-index,Java Essentials,Java Programming...
# 17
What happened here?jverd!!!! Your reporting abuse caused all this reply deleting!!!Luckily I saved all the thread, so I will put it all again, when I have time.
yamm_v5.0.20-alphaa at 2007-7-21 19:16:48 > top of Java-index,Java Essentials,Java Programming...
# 18
> Luckily I saved all the thread, so I will put it all> again, when I have time.Don't bother. You've had your mistake explained to you quite thoroughly, but you still refuse to see it. You're wasting time and bytes.
jverda at 2007-7-21 19:16:48 > top of Java-index,Java Essentials,Java Programming...
# 19
and pizza!
mkoryaka at 2007-7-21 19:16:48 > top of Java-index,Java Essentials,Java Programming...