const VS static final class variable ?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

const VS static final class variable ?

Garrett Smith
what is the difference between x1 and x2?

class A {
   const x1;
   static final x2;
}
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: const VS static final class variable ?

Brendan Eich-2
On Aug 17, 2007, at 1:10 PM, Garrett Smith wrote:

> what is the difference between x1 and x2?
>
> class A {
>    const x1;
>    static final x2;

You need a var before x2. Also you can't add final except before  
classes and methods (the reference implementation currently parses  
'class A { static final var x; }' but that's a bug).

Are you thinking of Java, or some other language here? If this is  
based on an ES4 example or spec, can you cite the URL?

The obvious difference, ignoring the intended illegality of static  
final var x2, is that x2 is static, so per class, not per instance.

/be
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: const VS static final class variable ?

Brendan Eich-2
On Aug 17, 2007, at 3:37 PM, Brendan Eich wrote:

> On Aug 17, 2007, at 1:10 PM, Garrett Smith wrote:
>
>> what is the difference between x1 and x2?
>>
>> class A {
>>    const x1;
>>    static final x2;
>
> You need a var before x2. Also you can't add final except before
> classes and methods (the reference implementation currently parses
> 'class A { static final var x; }' but that's a bug).
>
> Are you thinking of Java, or some other language here? If this is
> based on an ES4 example or spec, can you cite the URL?
>
> The obvious difference, ignoring the intended illegality of static
> final var x2, is that x2 is static, so per class, not per instance.

I should add that const is write-once, so you can have a const x1  
instance field. A constructor could write three different values to  
three different instances' x1 fields. In this case const does not  
mean per-class, as static const does, or a hypothetical static final  
var might.

/be

_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss