Joint types inconsistency: Suggesting we use & instead of | for exceptions.

Maurizio Cimadamore Maurizio.Cimadamore at Sun.COM
Tue Feb 2 06:34:13 PST 2010


Reinier Zwitserloot wrote:
> 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 think the semantics of T1 & T2 is rather different from the one of T1 
| T2:

*) T1 & T2 is a type T which is a subtype of both T1 and T2 (note that 
this type does not even exists in the case both T1 and T2 are 
classtypes, as in your example)
*) T1 | T2 is some type T which is *either* T1 or T2

The only similarity between the two types is that, from a type-checking 
perspective, T1 | T2 can be viewed as a type which has the same members 
as T1 & T2. But this is, an implementation aspect and I don't think we 
should base our syntax on how we are going to *implement* a given feature.

Maurizio
> 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