Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #653
| From | Lew <noone@lewscanon.com> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Why can one invoke setters and getters from a (class) constructor? |
| Date | 2011-04-25 15:14 -0400 |
| Organization | albasani.net |
| Message-ID | <ip4h5p$v3n$1@news.albasani.net> (permalink) |
| References | <87bozwkgz8.fsf@merciadriluca-station.MERCIADRILUCA> <0na8r6tg38fu60ojepfl5h4u20lmhfhffr@4ax.com> <fd44b4d4-872d-442c-93d3-a80761ac19ae@w9g2000prg.googlegroups.com> |
Fred wrote: > However, it can be dangerous for a constructor to call any method that > a subclass might override, because the superclass constructor would > then invoke the subclass method BEFORE the subclass constructor has > been called, and the subclass method may try to operate on subclass > variables that have not yet been created. > > Examples: Swing's JComponent constructor calls setBackground() and > setFont(). But if your component that is a subclass of JComponent is a > container that creates many other subcomponents, you might want your > setBackground() method to change the backgrounds of itself and all of > its subcomponents. But the JComponent constructor will invoke your > setBackground() before your constructor has created any of those > subcomponents. > > When I write constructors, they NEVER call any method that is not > private. or 'final' -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
Back to comp.lang.java.help | Previous | Next — Previous in thread | Find similar
Why can one invoke setters and getters from a (class) constructor? Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-23 19:36 +0200
Re: Why can one invoke setters and getters from a (class) constructor? Lew <noone@lewscanon.com> - 2011-04-23 13:58 -0400
Re: Why can one invoke setters and getters from a (class) constructor? markspace <-@.> - 2011-04-23 11:00 -0700
Re: Why can one invoke setters and getters from a (class) constructor? Merciadri Luca <Luca.Merciadri@student.ulg.ac.be> - 2011-04-23 23:53 +0200
Re: Why can one invoke setters and getters from a (class) constructor? Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-04-23 20:36 -0400
Re: Why can one invoke setters and getters from a (class) constructor? Lew <noone@lewscanon.com> - 2011-04-23 22:37 -0400
Re: Why can one invoke setters and getters from a (class) constructor? Roedy Green <see_website@mindprod.com.invalid> - 2011-04-24 06:53 -0700
Re: Why can one invoke setters and getters from a (class) constructor? Fred <fred.l.kleinschmidt@boeing.com> - 2011-04-25 11:06 -0700
Re: Why can one invoke setters and getters from a (class) constructor? Lew <noone@lewscanon.com> - 2011-04-25 15:14 -0400
csiph-web