Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Bulk Array Element Allocation, is it faster? Date: Sat, 24 Sep 2011 23:22:45 -0700 (PDT) Organization: http://groups.google.com Lines: 27 Message-ID: <32256761.625.1316931765221.JavaMail.geo-discussion-forums@prht31> References: Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 216.239.45.130 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1316931767 29114 127.0.0.1 (25 Sep 2011 06:22:47 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 25 Sep 2011 06:22:47 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=216.239.45.130; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8280 Roedy Green wrote: > The flat footed way to do a constructor is to zap the entire block to > 0, then go field by field initialised to non-null not-0 and plop that > value in on top. This "flat footed [sic] way" is what Java constructors do, and must. Member fields are set to their default values prior to any constructor assignment, even to the same value as the default. public class Foo { private Bar bar = null; } Foo#bar will be cleared to 'null' upon first construction, then initialized to 'null' by the explicit initialization. Both steps happen. Both steps are required to happen, and they're required to happen separately. > Because constructors are called so often, even a very minor > optimisation would pay off. Perhaps, depending on what you mean by "pay off". Some have argued that the optimization achieved by omitting explicit initialization to default values is not worth the supposed reduction in clarity. Since we all know that member fields are constructed with their default values, I don't think it's any less clear to omit their explicit (and redundant) initialization to default values. I guess it depends on whether that's your opinion, and whether omitting the redundant initialization is an optimization that would pay off. -- Lew