PROPOSAL: 'final' without explicit type (update)
Gabriel Belingueres
belingueres at gmail.com
Mon Mar 30 18:06:38 PDT 2009
2009/3/30 Marek Kozieł <develop4lasu at gmail.com>:
> W dniu 31 marca 2009 00:45 użytkownik Gabriel Belingueres
> <belingueres at gmail.com> napisał:
>> Hi Marek:
>>
>> - VariableInitializer type is neither primitive nor Object.
>> --> primitive : they should not be mixed with Object-s to easy.
>> --> Object : when object type is Object, we mostly deal with
>> situation 'Unknown type', so this should not be hidden.
>>
>> I still don't get why it is so bad to do something like this:
>> final a = 1; // static type is int
>> or
>> final o = new Object(); // static type is Object, no doubt
>>
>> I still don't see the point on not making this feature more orthogonal
>> (unless some convincing argument is presented against it.)
>>
>>
>
> For primitives I would prefer:
> primitive a = 1; // a is int / short / byte
> rather than:
> final a = 1; // static type is int
>
>
> Primitives represent other level of abstraction and mixing them will
> make people to be confused (more or less).
Why?
final a = 1; // static type is int
final b = new Integer(6); // static type is Integer
If this is confusing for someone:
final c = 1 + new Integer(7);
then declare it as usual.
> final o = new Object(); // in this form it's ok
>
> here I see problem:
> final o = some.getBoo().getLocalization(); // o is Object
>
> For some reason we did not ensured valid type to be returned, so we
> should care about it while declaring 'o', or say that we do not care:
> final o = (Localization) some.getBoo().getLocalization();
> final Object o = some.getBoo().getLocalization();
Assuming that getLocalization() returns a Localization, then the whole
point is that you don't need the cast; otherwise this feature is of
doubtful utility. The variable type is known at compile type to be a
Localization.
OTOH, if the getLocalization() returns an Object, then
final o = (Localization) some.getBoo().getLocalization();
might throw a ClassCastException at runtime, which is a pity because
this is a new feature.
If you want to risk to receive a ClassCastException, then declare it as usual:
final Localization o = (Localization) some.getBoo().getLocalization();
IMHO, type casts should be forbidden, or at least discouraged.
> If we allow final to be ANY type, then backing to declaration will be
> required just to make correction, this will piss off programmers.
>
> So primitives and Object-s are special types and should be handled in this way.
>
> --
> Pozdrowionka. / Regards.
> Lasu aka Marek Kozieł
>
> http://lasu2string.blogspot.com/
>
More information about the coin-dev
mailing list