You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Wes Wannemacher <we...@wantii.com> on 2009/06/03 17:02:19 UTC

use of private final vs. protected

I am looking at subclassing JakartaMultiPartRequest and almost all of
the members are 'private final', but they are Lists and Maps, so I am
curious what the justification is... I want to subclass and get at the
data, obviously I'd have to change the declarations to protected, but
is final necessary? From what I can see, the only thing it guarantees
is that with each instance of JakartaMultiPartRequest, the Lists or
Maps will point to new instances. I guess what I'm wondering is if
there is an intention to follow a coding standard or something that
I'm missing because I don't see much point for these members to be
private or final (especially since it makes it pretty much impossible
for me to subclass it).

-Wes

-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: use of private final vs. protected

Posted by Musachy Barroso <mu...@gmail.com>.
I think it is a case of "one standard per developer" :). IMO "private"
and "final" should be used carefully in a framework, as people are
always doing things we didn't expect them to do. I have that problem
at work, where I have to "copy and paste reuse" code, because parts
that I need to overwrite are private for no reason.

musachy

On Wed, Jun 3, 2009 at 8:02 AM, Wes Wannemacher <we...@wantii.com> wrote:
> I am looking at subclassing JakartaMultiPartRequest and almost all of
> the members are 'private final', but they are Lists and Maps, so I am
> curious what the justification is... I want to subclass and get at the
> data, obviously I'd have to change the declarations to protected, but
> is final necessary? From what I can see, the only thing it guarantees
> is that with each instance of JakartaMultiPartRequest, the Lists or
> Maps will point to new instances. I guess what I'm wondering is if
> there is an intention to follow a coding standard or something that
> I'm missing because I don't see much point for these members to be
> private or final (especially since it makes it pretty much impossible
> for me to subclass it).
>
> -Wes
>
> --
> Wes Wannemacher
> Author - Struts 2 In Practice
> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
> http://www.manning.com/wannemacher
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: use of private final vs. protected

Posted by Martin Cooper <ma...@apache.org>.
On Thu, Jun 4, 2009 at 7:21 AM, Wes Wannemacher <we...@wantii.com> wrote:

> On Thu, Jun 4, 2009 at 9:54 AM, Martin Cooper <ma...@apache.org> wrote:
> >
> >
> > Ha! Old code always comes back to haunt, no? ;-)
> >
> > Yep, I did a lot of work on that code a few years ago, partly in support
> of
> > Struts 1 and partly in support of extensibility (which I never got around
> to
> > documenting properly, but which worked like a charm). I handed the reins
> > over, though, at about the time the streaming API came along. While I
> also
> > did a lot of work on the S1 wrapper, I haven't even looked at the S2
> > wrapper, so I'm not sure you really want me messing with it. ;-) Still,
> if I
> > can find some time lurking under a rock somewhere, I can try to keep tabs
> on
> > what you're up to (assuming there's a "plan" of sorts).
>
> Am I supposed to plan? You might as well fire me now then :)


I used quotes advisedly. ;-) All I meant was that I can only realistically
comment on what you're doing if I have some idea of the end goal.

--
Martin Cooper



> -W
>
> --
> Wes Wannemacher
> Author - Struts 2 In Practice
> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
> http://www.manning.com/wannemacher
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>

Re: use of private final vs. protected

Posted by Wes Wannemacher <we...@wantii.com>.
On Thu, Jun 4, 2009 at 9:54 AM, Martin Cooper <ma...@apache.org> wrote:
>
>
> Ha! Old code always comes back to haunt, no? ;-)
>
> Yep, I did a lot of work on that code a few years ago, partly in support of
> Struts 1 and partly in support of extensibility (which I never got around to
> documenting properly, but which worked like a charm). I handed the reins
> over, though, at about the time the streaming API came along. While I also
> did a lot of work on the S1 wrapper, I haven't even looked at the S2
> wrapper, so I'm not sure you really want me messing with it. ;-) Still, if I
> can find some time lurking under a rock somewhere, I can try to keep tabs on
> what you're up to (assuming there's a "plan" of sorts).

Am I supposed to plan? You might as well fire me now then :)

-W

-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: use of private final vs. protected

Posted by Martin Cooper <ma...@apache.org>.
On Wed, Jun 3, 2009 at 8:23 AM, Wes Wannemacher <we...@wantii.com> wrote:

> On Wed, Jun 3, 2009 at 11:14 AM, Al Sutton <al...@funkyandroid.com> wrote:
> > Back in the dim and distant past I remember final being used to give the
> JIT an optimization hint that whatever's described as final can be inlined
> as it won't change (note JIT not compiler). It's not a big saving, but in
> tight loops and heavily called code it can all add up.
> >
> > I found http://www.javaperformancetuning.com/tips/final.shtml which
> expands on it a bit.
> >
> > Al.
> >
>
>
> That makes sense, Al, but in cases like this (non-primitives) all it
> does is finalize the reference. So the referred objects are not
> immutable, and I guess I was just wondering whether the optimization
> that final provides in this case is worth the pain it causes for
> subclassing.
>
> I agree with Musachy, we should be careful using private and final,
> especially in struts since we inject objects like this. I figured I
> could subclass it, make some changes and then have the plugin define a
> bean overriding the definition that comes from core. With the fields
> defined the way they are, it's not possible. I'll make the changes to
> JakartaMultiPartRequest, but wanted to make sure I wasn't breaking
> some rule.
>
> Funny side-note... So I was reading all the JavaDocs on commons
> file-upload and low-and-behold, who wrote most of the classes I was
> looking at? Our own Martin Cooper! So, Martin, you wanna help out with
> enhancing struts2 file uploading capabilities? 8-D


Ha! Old code always comes back to haunt, no? ;-)

Yep, I did a lot of work on that code a few years ago, partly in support of
Struts 1 and partly in support of extensibility (which I never got around to
documenting properly, but which worked like a charm). I handed the reins
over, though, at about the time the streaming API came along. While I also
did a lot of work on the S1 wrapper, I haven't even looked at the S2
wrapper, so I'm not sure you really want me messing with it. ;-) Still, if I
can find some time lurking under a rock somewhere, I can try to keep tabs on
what you're up to (assuming there's a "plan" of sorts).

--
Martin Cooper


-Wes
>
>
> --
> Wes Wannemacher
> Author - Struts 2 In Practice
> Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
> http://www.manning.com/wannemacher
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>

Re: use of private final vs. protected

Posted by Wes Wannemacher <we...@wantii.com>.
On Wed, Jun 3, 2009 at 11:14 AM, Al Sutton <al...@funkyandroid.com> wrote:
> Back in the dim and distant past I remember final being used to give the JIT an optimization hint that whatever's described as final can be inlined as it won't change (note JIT not compiler). It's not a big saving, but in tight loops and heavily called code it can all add up.
>
> I found http://www.javaperformancetuning.com/tips/final.shtml which expands on it a bit.
>
> Al.
>


That makes sense, Al, but in cases like this (non-primitives) all it
does is finalize the reference. So the referred objects are not
immutable, and I guess I was just wondering whether the optimization
that final provides in this case is worth the pain it causes for
subclassing.

I agree with Musachy, we should be careful using private and final,
especially in struts since we inject objects like this. I figured I
could subclass it, make some changes and then have the plugin define a
bean overriding the definition that comes from core. With the fields
defined the way they are, it's not possible. I'll make the changes to
JakartaMultiPartRequest, but wanted to make sure I wasn't breaking
some rule.

Funny side-note... So I was reading all the JavaDocs on commons
file-upload and low-and-behold, who wrote most of the classes I was
looking at? Our own Martin Cooper! So, Martin, you wanna help out with
enhancing struts2 file uploading capabilities? 8-D

-Wes


-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


RE: use of private final vs. protected

Posted by Al Sutton <al...@funkyandroid.com>.
Back in the dim and distant past I remember final being used to give the JIT an optimization hint that whatever's described as final can be inlined as it won't change (note JIT not compiler). It's not a big saving, but in tight loops and heavily called code it can all add up.

I found http://www.javaperformancetuning.com/tips/final.shtml which expands on it a bit.

Al.

-- 

* Written an Android App? - List it at http://andappstore.com/ *

======
Funky Android Limited is registered in England & Wales with the
company number  6741909. The registered head office is Kemp House,
152-160 City Road, London,  EC1V 2NX, UK.

The views expressed in this email are those of the author and not
necessarily those of Funky Android Limited, it's associates, or it's
subsidiaries.

-----Original Message-----
From: Wes Wannemacher [mailto:wesw@wantii.com] 
Sent: 03 June 2009 16:02
To: Struts Developers List
Subject: use of private final vs. protected

I am looking at subclassing JakartaMultiPartRequest and almost all of
the members are 'private final', but they are Lists and Maps, so I am
curious what the justification is... I want to subclass and get at the
data, obviously I'd have to change the declarations to protected, but
is final necessary? From what I can see, the only thing it guarantees
is that with each instance of JakartaMultiPartRequest, the Lists or
Maps will point to new instances. I guess what I'm wondering is if
there is an intention to follow a coding standard or something that
I'm missing because I don't see much point for these members to be
private or final (especially since it makes it pretty much impossible
for me to subclass it).

-Wes

-- 
Wes Wannemacher
Author - Struts 2 In Practice
Includes coverage of Struts 2.1, Spring, JPA, JQuery, Sitemesh and more
http://www.manning.com/wannemacher

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org