On Jan 27, 4:23 pm, Reinier Zwitserloot <[email protected]> wrote:
> They didn't bollocks up generics at all. They are fine as is.


Here are some things that IMHO would have made generics much better
without breaking backwards compatibility.  I think call of these could
still be done, in fact.

1) Optional definition site variance.  When I want co or contra-
variant type parameters now I have to litter my code with Foo<?
extends Bar> or Foo<? super Bar>.  It's so painful I mostly don't
bother making my types as general as they could be.
2) Some type inference, somewhere, please - without me having to write
static factory methods.  Before generics all the explicit type
annotations were mildly irritating.  After generics writing
Foo<Bar<Baz, Quux>> foo = new Foo<Bar<Baz, Quux>> is really, really,
really irritating.
3) Type aliasing (aka typedefs).  Same motivation as with type
inference, but type aliases can handle types that can't be inferred.
4) Deprecate "primitive" arrays and replace with properly generic type
constructor Array<T>.  Make  Array<T> invariant so that Array<String>
isn't an unsound subtype of Array<Object>.  The compiler would, of
course, emit the same code as arrays do now except that Array<T> would
erase to Object[] when there wasn't enough information for a more
specific type of array.
5) Root the type hierarchy above object so that primitives are part of
the hiearchy.  Allow generics to have primitive type parameters (e.g.
List<int>).  Implement by boxing if necessary for backward
compatibility, but make the null type not be a subtype of the
primitive types.  So List<Integer> could hold nulls but List<int>
couldn't (without casting or raw types or otherwise subverting the
type checker).
6) Relax some of the arbitrary limitations on wildcard bounds.
7) Add explicit types for Null and Void.


And one more incredibly irritating thing that should have been
addressed in the original design:
8) Don't call it "generics."  Call it parametric polymorphism, or type
constructors, or parametrized types, or "foozles."  I don't care, just
not "generics."  "Generic" subverts a nice word from being used to
describe all manner of generic programming techniques.


Now, if only there were a JVM language that got all of that right...
hmmmmm.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to