Re: Generics headache
Please do not top post.
Leonardo Teixeira Passos wrote:
In the presented code fragment (made just to present the problem, as
faithfully as the original one), yes, the type variable is not
necessary, but in the real code it is perfectly suitable and needed.
In case you are curious, feel free to browse the code in the CVS browser
for dcompframework, a SourceForge project. Comments are always welcome :)
My comments were based on the SourceForge source. I downloaded the whole
thing and set up a NetBeans project.
This is the code from the SourceForge version:
public abstract class Parser<ParserMatchingType> {
abstract public AST parse( Scanner scanner,
Map<String, LinkedList<String>> parameters )
throws Exception, ParseException, ScanException ;
public void doAfterEachMatch( ParserMatchingType value,
Map<String, LinkedList<String>> parameters ) {
/* By default do not do anything. */
}
}
The 'parse()' method makes no use of the type parameter 'ParserMatchingType'.
(Which latter would be named 'T' by convention.)
That's what makes the requirement to name the type in the 'Parser' inheritance
tree just to get at 'parse()' seem like there might be a refactoring needed.
--
Lew