RFR [9] 8071472: Add field access to support setting final fields in readObject
Alan Bateman
Alan.Bateman at oracle.com
Wed Mar 18 19:05:03 UTC 2015
On 18/03/2015 11:06, Chris Hegarty wrote:
> :
>
> /**
> * Checks that all final instance fields, declared by the class where
> * the {@code readObject} callback is being invoked, have been set.
> *
> * <p> This method is intended to be called as a final step after all
> * final instance fields have been set.
> *
> * @throws InvalidObjectException if one, or more, final instance
> * fields have not been set
> */
> void checkAllFinalsSet() throws InvalidObjectException;
>
>
> ...and the user code would look similar to this, from java.io.File:
>
> s.fieldSetter().set("path", p)
> .set("prefixLength", pLen)
> .checkAllFinalsSet();
I think this is a lot clearer as it makes it explicit and in addition it
is less confusing to have the InvalidObjectException thrown here rather
than somewhere in the deserialization code.
-Alan
More information about the core-libs-dev
mailing list