dev@javaserverfaces.java.net

Re: [REVIEW] Minor improvements to UIData

From: Adam Winer <adam.winer_at_oracle.com>
Date: Tue, 28 Aug 2007 10:57:20 -0700

Ed Burns wrote:
>>>>>> On Tue, 28 Aug 2007 09:42:08 -0700, Ryan Lubke <Ryan.Lubke_at_Sun.COM> said:
>
> RL> +
> RL> + /**
> RL> + * <p>Holds the base client ID that will be used to generate per-row
> RL> + * client IDs (this will be null if this UIData is nested within another).</p>
> RL> + */
> RL> + private String baseClientId;
>
> EB> If this is not a part of the saved state, mark it transient using the
> EB> "transient" java keyword.
>
> RL> Why? UIData isn't serializable.
>
> I like using transient to indicate that this ivar is clearly not a part
> of the saved and restored state. Also, just because UIData isn't
> serializable, doesn't mean someone somewhere will try to serialize an
> instance. I think we used to do that in our state saving implementation
> somewhere along the line anyway.

UIComponentBase isn't serializable - no one can ever
serialize a UIComponent, as you'd lose state from
the base class.

> EB> Also, I would like to have you explicitly
> EB> initialize this to "null" since you are counting on that being the
> EB> initial value in your new getClientId() method.
>
> RL> Why, Object members will be automatically initialized to null when
> RL> instantiated.
>
> Yes, this is true in Sun's implementation of the JLS, but perhaps it
> might not be true in another vendor's?

Yikes! No, it's true in every Java implementation
on the planet. null, 0, false are always the default
of every member variable or newly instantiated array. There's
zero reason to pre-initialize member variables to these.

-- Adam

>
> I'm just carrying over some philosophies from Effective C++ to Java and
> I think they still apply.
>
> Ed
>