Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #27590 > unrolled thread

Re: praise

Started byLew <lewbloch@gmail.com>
First post2014-02-25 15:01 -0800
Last post2014-03-04 13:06 -0600
Articles 3 — 3 participants

Back to article view | Back to comp.lang.java.programmer

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: praise Lew <lewbloch@gmail.com> - 2014-02-25 15:01 -0800
    Re: praise markspace <markspace@nospam.nospam> - 2014-02-25 16:46 -0800
      Re: praise Mike Amling <mamling@chaff.us> - 2014-03-04 13:06 -0600

#27590 — Re: praise

FromLew <lewbloch@gmail.com>
Date2014-02-25 15:01 -0800
SubjectRe: praise
Message-ID<b19ab8ff-6c01-4435-a38e-ab2b92dd584d@googlegroups.com>
Stefan Ram wrote:
>   One can even learn from it notions such as »package-tree
>   semantics« versus »traditional package semantics« or facts
>   such as »a class's constructors and methods can run prior to
>   its initialization« (»its« = »the class'«).

Strange. The JLS says:
http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.4
"A class or interface type T will be initialized immediately before the first occurrence of any one of the following:
 - T is a class and an instance of T is created.
 - T is a class and a static method declared by T is invoked.
 - A static field declared by T is assigned.
 - A static field declared by T is used and the field is not a constant variable (§4.12.4).
 - T is a top level class (§7.6), and an assert statement (§14.10) lexically nested within T (§8.1.3) is executed."

So that contradicts.

-- 
Lew

[toc] | [next] | [standalone]


#27592

Frommarkspace <markspace@nospam.nospam>
Date2014-02-25 16:46 -0800
Message-ID<lejdhe$9m5$1@dont-email.me>
In reply to#27590
On 2/25/2014 3:01 PM, Lew wrote:

> Stefan Ram wrote:
>>    One can even learn from it notions such as »package-tree
>>    semantics« versus »traditional package semantics« or facts
>>    such as »a class's constructors and methods can run prior to
>>    its initialization« (»its« = »the class'«).

>
> Strange. The JLS says:
> http://docs.oracle.com/javase/specs/jls/se7/html/jls-12.html#jls-12.4
> "A class or interface type T will be initialized immediately before the first occurrence of any one of the following:
>  [the class is used]
> So that contradicts.
>

The paragraph Stefan is referring to, I think, is:

" There is, however, one corner case that demands special treatment. It 
is possible, though generally not desirable, to execute methods or 
constructors prior to initialization. This can happen when a class 
hierarchy contains a circularity in its static initialization."

So it looks to me like the JLS is implying a "best effort" to initialize 
a class before it is used, but can't absolutely guarantee it in all cases.

It would be an interesting experiment to try to write some code to 
reproduce the case where a ctor is called before its initialization.

[toc] | [prev] | [next] | [standalone]


#27681

FromMike Amling <mamling@chaff.us>
Date2014-03-04 13:06 -0600
Message-ID<bnmmbqF9ugmU1@mid.individual.net>
In reply to#27592
On 2/25/14 6:46 PM, markspace wrote:
> It would be an interesting experiment to try to write some code to
> reproduce the case where a ctor is called before its initialization.

class Foo {
  static Foo baz=new Foo();
  static Object what=new Object();

  Foo() {
   System.out.println(what);
  }
}

It's easy enough to run a constructor before class initialization is 
complete. Offhand, I don't see how one would run a constructor before 
class initialization begins.

Mike Amling
--
"We will bury you." -Nikita Kruschev

Nikita Kruschev is buried at Novodevichy Cemetery, Moscow.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web