Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!postnews.google.com!m3g2000pre.googlegroups.com!not-for-mail From: lewbloch Newsgroups: comp.lang.java.programmer Subject: Re: Getter/Setter - Serialization Date: Sun, 24 Jul 2011 11:51:10 -0700 (PDT) Organization: http://groups.google.com Lines: 37 Message-ID: <920e6278-32ed-44ea-8a61-d1c38f531816@m3g2000pre.googlegroups.com> References: NNTP-Posting-Host: 216.239.45.130 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1311533470 26093 127.0.0.1 (24 Jul 2011 18:51:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 24 Jul 2011 18:51:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: m3g2000pre.googlegroups.com; posting-host=216.239.45.130; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: ASELCHRU X-HTTP-UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.99 Safari/535.1,gzip(gfe) Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:6515 On Jul 24, 8:07=A0am, Thomas Lehmann wrote: > Hi, > > probably a silly question. I have a class and some members will be > initialized only when calling a 'create' method. I'm using Eclipse and > there I get a warning "Found non-transient, non-static member. Please > mark as transient or provide accessors." > > My question is now how to handle it correct. When I provide a setter > (assume a creation date) then I could set the creation date to another > as initialized when calling 'create'. That's why I wouldn't provide a > setter for this member. But obviously the warning want to tell me that Did you declare the attribute as 'final'? If you want to protect a member variable from change, that's often the best way. It has other benefits as well. > I might have problems with the serialization then obviously requiring > that the setter exists (and yes I'm intending to do serialization - > probably XML). > > Could you please give some helpful comments on this? Could you please give us an SSCCE? http://sscce.org/ As markspace points out, we need some context here. To grok serialization, you should rigorously study the material in Joshua Bloch's seminal book /Effective Java/, which thoroughly covers the risks and best practices involved. http://java.sun.com/docs/books/effective/ Chapter 11 -- Lew