Olivier Lefevre schrieb:
> Johannes Luber wrote:
>> I've noticed following new addition to the Token class:
>>
>> public static final Set legalOptions = new HashSet() {
>> { add(defaultOption); }
>> };
>>
>> Can someone explain me, what that code snippet actually does?
>
> I think some of the explanations given before were a bit confused
> or perhaps even wrong.
>
> 1) legalOptions is a static instance of an anonymous subclass of
> HashSet. Thus it _cannot_ cannot have any explicitly declared
> constructor (JLS §15.9.5.1): instead, a default one is provided,
> as always (JLS §8.8.7).
>
> 2) The { add(defaultOption); } block is an instance initializer
> (JLS §8.6) that is executed before the constructor.
>
> The first point explains the second one: Ter wants to initialize
> the set with a defaultOption element but cannot do so in a
> constructor since he is not allowed to provide any explicit one
> and the default one is synthetic and therefore off-limits, too.
>
> Hopes this clears the air: you all have been generous with
> explanations in the past, so I thought I'd be the lecturer
> for a change ;-)
>
> -- O.L.
Thanks for the enlightenment - this is more an obscure Java feature than
something a neophyte would ever consider. Micheal's C# translation shows
that Java lacks clarity unnecessarily.
Johannes
_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org:8080/mailman/listinfo/antlr-dev