L
Lew
Arne said:It was new syntax when it was added.
So was the "assert" keyword. So were anonymous classes. Heck, the Java
language itself was new when it first came out. Come on.
Arne said:It was new syntax when it was added.
You did one of the things I like to see in docs, start with the simple
case and gradually add the complexities.
Lew said:So was the "assert" keyword. So were anonymous classes. Heck, the Java
language itself was new when it first came out. Come on.
Arne said:Most new features add complexity.
That was the point in what I was trying to explain.
New features adds complexity whether they add new keywords or
not. So "<T>" or "of T" does not make a big difference in
the complexity added.
I had that "ah-hah" moment. I'm sorry that you haven't, yet.
What List[Integer] has going for it is that the array syntax fits closer
into a notation of what a generics type generally does: it's a container
of some object. On the other hand, it looks like an array access, which
means that the parser would look rather interesting.
What List[Integer] has going for it is that the array syntax fits closer
into a notation of what a generics type generally does: it's a container
of some object. On the other hand, it looks like an array access, which
means that the parser would look rather interesting.
Introducing new keywords is an issue I didn't discuss, but suffice to
say that it's something that many of the people with a say in the future
of Java want to avoid.
Roedy said:& is used where you would expect to use comma. extends is used where
you would expect to use implements. super does not mean super.
So was the "assert" keyword. So were anonymous classes. Heck, the Java
language itself was new when it first came out. Come on.
Why would "implements" be better than "extends"? The supertype doesn't
have to be an interface. The idea of "extension" is much more natural
for type analysis than "implementation".
And how does "super" not mean super? The type that is "super" ('?' in
the example here) is a supertype; using "super" as the keyword seems
entirely natural.
And why are we bitching about this five-year-old syntax anyway? It's a done
deal.
Java already has generics defined the way Java already has generics
defined. It will be far, far more productive to learn the syntax than
to try to change it.
The "?" can represent either a class that implements Runnable or an
interface that extends it. There are a total of three cases, class
extends class, interface extends interface, and class implements
interface. "extends" is appropriate for two of the cases, and the same
keyword has to handle class implements interface and interface extends
interface, so I think "extends" is the less bad choice.
Perhaps it was a mistake to use a special keyword for introducing an
interface in a class declaration. If the superclass and all interfaces
had been introduced by "extends" the problem would not exist.
In the first statement of a constructor, "super" introduces the
superclass constructor parameter list. It has never had only one meaning.
In general, Java has gone with a strategy of a short list of reserved
words, recycling them to deal with several related concepts whenever
possible in preference to adding new ones. The most extreme case of this
is "static".
this code snippet does not compile: the contents of 'a' cannot be
silently converted to the 'List<Object>' type. Why so ? Because the list
instance does NOT know it element type. Generics work by so-called 'type
erasure'
Roedy said:That is one of my conjectures, that type erasure was a wrong-headed
idea. It weakened and complicated generics too much. Surely, it is
not
inherent to the notion that containers should be type safe.
Roedy said:That is one of my conjectures, that type erasure was a wrong-headed
idea. It weakened and complicated generics too much. Surely, it is not
inherent to the notion that containers should be type safe.
Lew said:I like type erasure. It keeps one from the temptation to use
genericity as an operational concept as opposed to a declarative
one.
Mike said:I almost know what this means, but every time I think I've grasped it,
my hand seems to be empty. Could you elaborate?
Lew said:As it stands, generics provide a compile-time contract for
declarations about type relationships. In order to get run-time
behavior, i.e., operational use of type information you need to
provide a Class object; type parameters don't permit any run-time
operations.
The result is that generics provide compile-time assertions that
code
will not throw a ClassCastException or other type-related problem.
Erasure guarantees that this safety carries no run-time overhead.
Run-time generics would sacrifice this efficiency and tempt us to
patch holes in the type analysis with procedural hacks. Instead of
analyzing the types we'd coerce them. Java still lets you do
run-time type tricks with a type token (Class object), but type
parameters are reserved for assertions about type relationships.
This forces us to deal with type problems at compile time.
Peter said:Though, .NET illustrates that an alternative approach would have
been
to simply create a new, parallel group of classes supporting
generics, rather than to insist that the old classes be reusable via
generics.
Mike said:Erasure is needed for compatibility with the non-generic version of
the type, and that's the only reason it exists. If generics had been
present from the beginning, the type parameters would be first-class
parts of the type, just as they are for arrays. (And just as they
are in .NET, where generics were used only in newly introduced
classes.)
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.