Re: JLS 3/e -- Lots Of Errors
On 02/04/2011 08:37 PM, Lawrence D'Oliveiro wrote:
Here???s another fun one.
In section 4.8, on page 58, it says:
The use of raw types is allowed only as a concession to compatibility of
legacy code. The use of raw types in code written after the introduction
of genericity into the Java programming language is strongly
discouraged. It is possible that future versions of the Java programming
language will disallow the use of raw types.
(That last sentence is in bold.) However, in the discussion on page 136:
Note that expression names may be qualified by type names, but not by
types in general. A consequence is that it is not possible to access a
class variable through a parameterized type
class Foo<T> {
public static int classVar = 42;
}
Foo<String>.classVar = 91; // illegal
Instead, one writes
Foo.classVar = 91;
This does not restrict the language in any meaningful way. Type
parameters may not be used in the types of static variables, and so the
actual parameters of a parameterized type can never influence the type
of a static variable. Therefore, no expressive power is lost.
Technically, the type name Foo above is a raw type, but this use of raw
types is harmless, and does not give rise to warnings.
So one the one hand raw types are deprecated, but on the other hand they are
the only permitted way to access static fields of a parameterized type.
That is neither an error nor a typo, nor sloppy, but a precise description of
the actual rules.
You may think the rules are screwy, but the JLS itself is not sloppy nor
erroneous there.
--
Lew
Ceci n'est pas une fen??tre.
..___________.
|###] | [###|
|##/ | *\##|
|#/ * | \#|
|#----|----#|
|| | * ||
|o * | o|
|_____|_____|
|===========|