Re: Generics headache
On Sun, 27 Jul 2008, Leonardo Teixeira Passos wrote:
"CupParser is not abstract and does not override abstract method
parse(java.util.Map) in Parser public class"
I put this (in a file Teix.java) through Sun javac 1.5.0_13 (on the Mac,
FWIW), and got the following:
Teix.java:27: CupParser is not abstract and does not override abstract
method parse(java.util.Map) in Parser
class CupParser extends InterceptableParser<Object, Object> {
^
1 error
Which is the same as you got with OpenJDK.
I have to say, i'm stumped. Saying that CupParser doesn't override parse
is just plain wrong.
My only thought is that it's to do with the declaration of
InterceptableParser. If you'll recall, Parser is:
abstract class Parser<ParserMatchingType>
and InterceptableParser is:
abstract class InterceptableParser<ExternalParserClass, MatchingType> extends Parser
Note that InterceptableParserextends Parser - *not* Parser<MatchingType>.
That means that there's a type variable, Parser.ParserMatchingType (or
however you write it) that hasn't been bound at any point. That means that
the types of Parser and CupParser are subtly different in some deep and
mysterious way.
So, what happens if you change the declaration of InterceptableParser to:
abstract class InterceptableParser<ExternalParserClass, MatchingType> extends Parser<MatchingType>
?
Aha! With the Sun javac, that magically fixes the compilation error!
tom
--
Initial thoughts - who cares? Subsequent thoughts - omg!!! (Female, 14,
Scotland) -- 4.5 million young Brits' futures could be compromised by
their electronic footprint, Information Commissioner's Office