On Jan 28, 5:10 pm, Reinier Zwitserloot <[email protected]> wrote:
> Ben, James:
>
> but about the ability to declare an
> entire type array-style subtypable in a pinch.

Except that Java's array covariance isn't statically type safe, and
except that we also want contravariance, yes you have the idea.  But
not "in a pinch." It's a generally useful concept.


> Which uses cases exist for that mechanism other than 'this class is
> immutable, and therefore won't break under covariance'? Because if
> that's the only case, I say: Add a rigidly checked immutability
> modifier to the language itself and automatically make the type
> covariant across the board.

You need both co and contra variant type parameters and and you need
to somehow enforce the separation of in and out parameters across the
subtypes - a subclass can't add a method and use a covariant type in
contravariant position.  The issue is only tangentially related to
immutability.

As for use cases, remember that "generics" are about far more than
just collections. For instance, you want closures and one natural way
to model a one argument closure in an OO language using C# syntax is
as an instance of "interface Function<in ArgType, out ResultType>
{public ResultType apply(ArgType arg);}".  Now, whether Java actually
goes that route is irrelevant.  It's just indicative of
how...generic...the idea is.

> Java doesn't have that many immutable structures and even fewer
immutable structures that have a generics parameter.

"Java" the language has a ton of immutable, generic structures whether
or not the standard library has them.  I know because many are in my
code.  Why is a language feature only useful if it's used by the
standard library?  Java is a general purpose programming language.
That means you can even use it to do more than just glue standard
library bits together (gasp!).

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