when & why to make a class final  
Author Message
Petterson Mikael





PostPosted: 2005-8-16 15:12:00 Top

java-programmer, when & why to make a class final Hi,

Can anyone explain when and why to make a class final?

//mikael
 
Stefan Schulz





PostPosted: 2005-8-16 16:06:00 Top

java-programmer >> when & why to make a class final On Tue, 16 Aug 2005 09:11:55 +0200, Petterson Mikael wrote:

> Hi,
>
> Can anyone explain when and why to make a class final?

If the class somehow intrinsically is critical to behave exactly the way
you specified, including internals like representation of data and so on,
and subclasses would necessarily break this function. (Like
java.lang.Class)

--
You can't run away forever,
But there's nothing wrong with getting a good head start.
--- Jim Steinman, "Rock and Roll Dreams Come Through"


 
Petterson Mikael





PostPosted: 2005-8-16 18:59:00 Top

java-programmer >> when & why to make a class final Stefan Schulz wrote:
> On Tue, 16 Aug 2005 09:11:55 +0200, Petterson Mikael wrote:
>
>
>>Hi,
>>
>>Can anyone explain when and why to make a class final?
>
>
> If the class somehow intrinsically is critical to behave exactly the way
> you specified, including internals like representation of data and so on,
> and subclasses would necessarily break this function. (Like
> java.lang.Class)
>

Hmmm what is the meaning of intrinsically?
What will final tell about the class? Can data not be changed?
How can subclasses break this function if class is not final?

cheers,

//mikael
 
 
jAnO!





PostPosted: 2005-8-16 19:13:00 Top

java-programmer >> when & why to make a class final
"Petterson Mikael" <email***@***.com> wrote in message
news:ddsgt6$v0k$email***@***.com...
> Stefan Schulz wrote:
> > On Tue, 16 Aug 2005 09:11:55 +0200, Petterson Mikael wrote:
> >
> >
> >>Hi,
> >>
> >>Can anyone explain when and why to make a class final?
> >
> >
> > If the class somehow intrinsically is critical to behave exactly the way
> > you specified, including internals like representation of data and so
on,
> > and subclasses would necessarily break this function. (Like
> > java.lang.Class)
> >
>
> Hmmm what is the meaning of intrinsically?
> What will final tell about the class? Can data not be changed?
>
You make a class final so that it can't be extended, thus preventing other
client programmers from changing your implementation.

> How can subclasses break this function if class is not final?

A subclass can override the methods from the baseclass, that's the whole
point.


 
 
Petterson Mikael





PostPosted: 2005-8-16 19:21:00 Top

java-programmer >> when & why to make a class final jAnO! wrote:
> "Petterson Mikael" <email***@***.com> wrote in message
> news:ddsgt6$v0k$email***@***.com...
>
>>Stefan Schulz wrote:
>>
>>>On Tue, 16 Aug 2005 09:11:55 +0200, Petterson Mikael wrote:
>>>
>>>
>>>
>>>>Hi,
>>>>
>>>>Can anyone explain when and why to make a class final?
>>>
>>>
>>>If the class somehow intrinsically is critical to behave exactly the way
>>>you specified, including internals like representation of data and so
>
> on,
>
>>>and subclasses would necessarily break this function. (Like
>>>java.lang.Class)
>>>
>>
>>Hmmm what is the meaning of intrinsically?
>>What will final tell about the class? Can data not be changed?
>>
>
> You make a class final so that it can't be extended, thus preventing other
> client programmers from changing your implementation.
>
>
>>How can subclasses break this function if class is not final?
>
>
> A subclass can override the methods from the baseclass, that's the whole
> point.
>
>
Thanks for the clear explanation!

//Mikael