PROPOSAL: 'final' without explicit type
Florian Weimer
fw at deneb.enyo.de
Sun Mar 29 05:23:19 PDT 2009
* Reinier Zwitserloot:
> final list = foo ? new LinkedList() : new ArrayList();
>
> the type of 'list' is what, exactly?
It's the type specified in section 15.25 of the JLS. I can't find a
definition of lub(T1, T2) in the spec, but "lub" probably stands for
"least upper bound", and lub(LinkedList, ArrayList) would be
AbstractList & Serializable & Cloneable (if I got the types right).
> Serializable? Cloneable? List? They're all valid, so that wouldn't
> work.
Intersection types are already part of the language, so I don't see
any problem. The following compiles:
interface I1 {}
interface I2 {}
static class C1 implements I1, I2 {}
static class C2 implements I1, I2 {}
static <T extends I1 & I2> void foo1(T foo) {
}
static void foo1(boolean foo) {
foo1(foo ? new C1() : new C2());
}
Existence of intersection types also leaks to the surface during
overload resolution.
It's just that you can't write down the type of some expressions using
Java type notation. For local variables, this isn't a problem; only
debugging information needs to be updated slightly. The effect for
fields would be more pronounced, and I guess to stay within COIN's
scope, a proposal would have to exclude inference for fields.
More information about the coin-dev
mailing list