PROPOSAL: 'final' without explicit type
develop4lasu at gmail.com
Fri Mar 27 20:24:02 PDT 2009
W dniu 26 marca 2009 22:41 użytkownik Gabriel Belingueres
<belingueres at gmail.com> napisał:
> VariableInitializer type is neither primitive nor Object. Why?
primitive: are 'special' and they should not be mixed with objects to much.
Object: this is more complicated situation.
final some = null;
have no sense at all, it's just new name for something common.
Similar situation overlap with Objects, so while we do not know that
type we have, then omitting 'this' type have no sense as well, because
we loose information 'this object type is unknown'.
> Also, there are times when it might be OK to assign null to a variable
> as long as the compile time type can be uniquely identified:
> final a = (booleanCondition) ? null : new SomeClass();
> In this case the you can assume that the type of variable a will be SomeClass.
> What about autoboxing?
> final a = (booleanCondition) ? 1 : new Integer(2);
Forbid (at least in first version).
> it is int or Integer? (currently the ? operand resolve it to an int)
> Also see my notes on the interaction between final variables and overloading:
> IMO, when using the ? operator it should not try to find an
> intersection type for the compile time type of the final variable, but
> it should be the exact type on both the 2nd and 3rd operand, otherwise
> it should raise a compiler error. If you want another type for the
> variable, then specify it as usual.
I agree, except @see previous mail.
Pozdrowionka. / Regards.
Lasu aka Marek Kozieł
More information about the coin-dev