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 ?
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() );
}
> 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.