why transient variable can not be final?

Discussion in 'Java' started by Thomas Hawtin, Apr 13, 2006.

  1. wrote:
    > why transient variable can not be final?


    They can, but it can be difficult to make use of.

    As readObject is only a "psuedo-constructor", it cannot initialise final
    fields. ObjectInputStream will create the object with null/0/'\0'/false
    for that field.

    There are a few ways around this. java.util.Random in 1.6 cheats by
    using sun.misc.Unsafe. It may be possible to introduce a superclass that
    does not implement java.io.Serializable but has the field with
    appropriate initialisation (unlike Serializable subclasses, it's no-arg
    constructor will be called). Or you can use readResolve to construct a
    replacement object (this does not play so well with inheritance).

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Apr 13, 2006
    #1
    1. Advertising

  2. Thomas Hawtin

    Guest

    why transient variable can not be final?
    , Apr 13, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TmVsc29uIFAuIFZhcmdoZXNl?=

    Disable Session or Transient Cookies

    =?Utf-8?B?TmVsc29uIFAuIFZhcmdoZXNl?=, Jul 26, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    417
    =?Utf-8?B?TmVsc29uIFAuIFZhcmdoZXNl?=
    Jul 26, 2005
  2. Se-Jin Park
    Replies:
    1
    Views:
    4,569
    Chris Smith
    Nov 18, 2004
  3. Replies:
    3
    Views:
    20,900
    Roedy Green
    Jan 21, 2006
  4. smackedass
    Replies:
    5
    Views:
    490
    Daniel R. Tobias
    Aug 9, 2004
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,762
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page