Joint types inconsistency: Suggesting we use & instead of | for exceptions.
Reinier Zwitserloot
reinier at zwitserloot.com
Tue Feb 2 05:53:22 PST 2010
In generics, there's a concept that's fairly close to a joint type, which
involves the ampersand (&) character:
public class Foo<T extends List & Serializable> {}
However, in the proposed (draft v0.1) closure syntax, | is used to make a
"joint type" for exceptions:
#int(int, int)(throws IOException|SQLException) x;
While the exception list there isn't really a single (joint) type, there are
some conceptual similarities, and it makes a lot more sense to say that a
method throws both IOException and SQLException, than to say it throws
either IOException or SQLException (checked exceptions are interesting on
the type level to track what you need to catch, and if a method can throw
either, then you need to catch both in order to satisfy javac, hence, it
makes more sense to consider this a joint type instead of a disjoint type).
I therefore suggest the syntax is changed to:
#int(int, int)(throws IOException & SQLException) x;
the side benefit of a bar being hard to differentiate from an uppercase i or
a lowercase L in many fonts whereas the ampersand is always distinctive is
extra gravy. &, of course, invokes thoughts of 'and', whereas the bar
invokes thoughts of 'or', given that they are used in the and or op
operators in java.
NB: Is there any reason why it can't mirror method declarations and use
commas?
--Reinier Zwitserloot
More information about the lambda-dev
mailing list