Multiple function signatures in .tag file

I'm writing a jsp .tag file and I've encountered the following problem. I have those two functions :

privatevoid iterateThroughChildElements(Element element)

{

for (Iterator i = question.getElements().iterator(); i.hasNext(); )

this.parseAndDisplay( (Element) i.next() );

}

privatevoid parseAndDisplay(Question question)

{

(......)

privatevoid parseAndDisplay(Answer question)

{

(......)

Both Answer and Question objects are elements but I get an error from the compiler which says that no correct signature was found for the parseAndDisplay function.

What could be the problem ? Do I have to cast the objects according to a instanceof comparaison ?

[1074 byte] By [lucboudreaua] at [2007-10-2 18:06:38]
# 1

There was an error in my code, it is as follows :

private void iterateThroughChildElements(Set elements)

{

for (Iterator i = elements.iterator(); i.hasNext(); )

this.parseAndDisplay( (Element) i.next() );

}

lucboudreaua at 2007-7-13 19:26:07 > top of Java-index,Other Topics,Patterns & OO Design...
# 2

> Both Answer and Question objects are elements but I

> get an error from the compiler which says that no

> correct signature was found for the parseAndDisplay

> function.

The compiler is borking with the following line this.parseAndDisplay( (Element) i.next() ); You are telling it you are passing an (Element) but you have only implemented the specific function for (Question) and (Answer).

> What could be the problem ? Do I have to cast the

> objects according to a instanceof comparaison ?

Use polymorphism and add the function

private void parseAndDisplay((Element) element) {

element.parseAndDisplay() ;

}

Then move the parse and display functionality from this class into the similar named functions in the Question and Answer classes.

MartinS.a at 2007-7-13 19:26:07 > top of Java-index,Other Topics,Patterns & OO Design...