Uhhhh... After reading your complaint, I think I just misunderstood
your objection in the getClass() is incorrect synchronization object
which I agree with. The direct reference to the superclass object
instance is what should be done. I just got 'jumpy' when I read that
"getClass() in a constructor can return different class object
instances" as if that was true for instantiation of same Type. And the
only thing you are really saying is true in both constructors and any
other method for that matter.

Sorry for the noise.

Cheers
Niclas

On Tue, Feb 8, 2011 at 5:04 PM, Patricia Shanahan <p...@acm.org> wrote:
> On 2/7/2011 11:59 PM, Niclas Hedhman wrote:
>>
>> On Tue, Feb 8, 2011 at 12:00 PM, Patricia Shanahan<p...@acm.org>  wrote:
>>
>>> The synchronization is ineffective, because getClass() can return
>>> different
>>> Class objects in a non-final class' constructor.
>>
>> This is important news to me... Are you sure about that? Got any JLS
>> reference/pointer?
>
> It is a logical consequence of two basic facts. If you doubt either or both
> of them, tell me and I'll dig up the references:
>
> 1. There is an explicit or implicit call to a superclass constructor at the
> start of any constructor that does not begin with a "this" call, other than
> the Object constructor.
>
> 2. getClass() returns a reference to the class object for the method
> invocation target, not the class object for the class containing the call to
> getClass().
>
> Here is a trivial program illustrating the effect:
>
> public class GetClassTest {
>  public static void main(String[] args) {
>    new GetClassTest();
>    new Sub1();
>    new Sub2();
>    new SubSub();
>  }
>
>  GetClassTest() {
>    System.out.printf(
>      "Class object toString \"%s\", Class object hashcode %d%n",
>        getClass(),
>        getClass().hashCode());
>  }
> }
>
> class Sub1 extends GetClassTest {
> }
>
> class Sub2 extends GetClassTest {
> }
>
> class SubSub extends Sub1 {
> }
>
>
> The output is:
>
> Class object toString "class GetClassTest", Class object hashcode 2106235183
> Class object toString "class Sub1", Class object hashcode 729943514
> Class object toString "class Sub2", Class object hashcode 646414701
> Class object toString "class SubSub", Class object hashcode 2131949076
>
> Patricia
>



-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I live here; http://tinyurl.com/3xugrbk
I work here; http://tinyurl.com/24svnvk
I relax here; http://tinyurl.com/2cgsug

Reply via email to