Java initializer block syntax

Jason Johnson jason.johnson.081 at gmail.com
Tue Oct 9 19:54:59 UTC 2007


Well, that's basically instance variable declarations and methods to
initialize them as I recall.  That is, I don't think you can call a
"side effects only" function there.

But in any case, what brings it up?  Are you wishing Smalltalk had
this?  Because personally I like the way Smalltalk world works as
apposed to the C++/Java world of magic functions getting implicitly
called in orders one must memorize.

In Smalltalk there are (normally) functions getting called on creation
but you don't have to memorize it, it's in the code where you can read
it.

On 10/9/07, Damien Cassou <damien.cassou at gmail.com> wrote:
> Hi,
>
> I discovered that the following syntax is valid Java code:
>
> class A {
>
>   {
>       /* any java code here */
>   }
>
> }
>
>
> This code will be executed just before the constructor. I haven't
> found any use for this syntax, even in the case of subclasses.
>
> Does anyone have any idea or is it just useless?
>
> --
> Damien Cassou
>
>



More information about the Squeak-dev mailing list