What hole do you see in Scala and C# if covariance and contravariance open holes in type safety? There may well be a problem I don't know of.
As for Monad (or higher kinds in general), I'll try to come up with a motivating example at some point but I'm self-trained to avoid it in Java mainly because the missing feature makes it hard. On Jul 30, 2012 3:20 PM, "Fabrizio Giudici" <[email protected]> wrote: > On Mon, 30 Jul 2012 14:55:30 +0200, Ricky Clarkson < > [email protected]> wrote: > > Java type-system issues: >> >> 1. Arrays.asList("foo", "bar") gets the type List<String> when it's the >> only thing in the expression, but as soon as you pass it to something else >> the type parameter gets inferred to be Object. >> > > Ok, I call this minor. > > 2. No way of saying that an Iterator<String> is an Iterator<Object> even >> though logically it could be (no covariance or contravariance) >> > > This is a major pain, but I still have to see an explanation that shows > that covariance in generics doesn't open a serious hole in type safety. > > 3. Arrays are covariant so the compiler lets you add an invalid item to an >> array. >> > > Ditto. > > 4. List<int> doesn't work. Nothing to do with erasure, as Scala manages >> it. >> > > Agreed, this is major. But now please tell me how Scala does it :-). > > 5. null inhabits every reference type (like in lots of other mainstream >> languages). >> > > This is complex to debate. In any case, I wouldn't expect anything > different from an industrial, general purpose language from the '90s. > > 6. foreach is not open for extension, i.e., it only works with Iterables >> and arrays. >> > > I call this minor. > > 7. try-with-resources is not open for extension, e.g., it can't be made to >> work with locks without wrapper objects. >> > > try-with-resources is completely useless. Lombok's @Cleanup is at least as > robust and more flexible. > > 8. Varargs use arrays. Given the incompatibility between generics and >> arrays (caused by arrays' covariance) this just seems a mistake. Again, >> should be open for extension. >> > > Medium level. > > 9. No higher kinds. I can't write Monad in Java because there's no way of >> saying "this type parameter has a type parameter". This occasionally >> results in either code with warnings or duplication. >> > > I call this minor, unless somebody shows me how Monads would make my life > so much better. > > > -- > Fabrizio Giudici - Java Architect, Project Manager > Tidalwave s.a.s. - "We make Java work. Everywhere." > [email protected] > http://tidalwave.it - http://fabriziogiudici.it > -- You received this message because you are subscribed to the Google Groups "Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
