Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #24579
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: multiple inheritance in Java |
| Date | 2013-07-02 08:17 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <kqug27$6kg$1@dont-email.me> (permalink) |
| References | <multiple-inheritance-20130702024630@ram.dialup.fu-berlin.de> <kqtbs2$ou6$1@dont-email.me> <multiple-inheritance-20130702042118@ram.dialup.fu-berlin.de> <kqtkmm$4ac$1@dont-email.me> <multiple-inheritance-20130702114901@ram.dialup.fu-berlin.de> |
On 7/2/2013 5:49 AM, Stefan Ram wrote:
> Eric Sosman <esosman@comcast-dot-net.invalid> writes:
>> So, just a struct?
>
> Yes. Recently, I often had this thought, that sometimes
> structs are appropriate.
>
>> Yeah, but they are references to objects with non-final fields.
>> If thread T1 does cp.color.setR(42) and T2 does r=pc.color.getR()
>> while cp and pc refer to the same ColorPoint instance (or to distinct
>> ColorPoint instances that refer to the same Color instance), you've
>> got a race.
>
> How do you know the author of Color has not taken care for
> proper synchronisation? IMHO, this is a question of thread-safety
> of the Color class not of the ColorPoint class.
Not enough, because the constraint applies to both the
Color and Position classes simultaneously. Even if both of
those classes are individually thread-safe, the combination
isn't. If actions A1 and A2 are atomic, it does not follow
(in fact, almost never follows) that A1;A2; is atomic.
>> ... and suddenly I've got constraints not anticipated by the
>> original author -- without changing a single line of his code.
>> With (overridable) accessors I could manage those constraints;
>> with exposed fields I could not.
>
> I see, so I should declare the class final.
Right. Inheritance is for *your* benefit alone, and you
should make sure nobody else can use it. ;-)
--
Eric Sosman
esosman@comcast-dot-net.invalid
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: multiple inheritance in Java markspace <markspace@nospam.nospam> - 2013-07-01 18:59 -0700
Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 00:30 -0400
Re: multiple inheritance in Java Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-07-02 08:17 -0400
Re: multiple inheritance in Java Arne Vajhøj <arne@vajhoej.dk> - 2013-07-04 16:31 -0400
csiph-web