• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doStartTag valid return checked @ compile time??

 
amol re
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming the rest of the code is valid,
which is true about this code?
public class TestTag extends TagSupport{
public int doStartTag(){
try{
JspWriter out=pageContext.getOut();
out.println("Customize");
}//try
catch(IOException ioex){}
return(EVAL_BODY_BUFFERED);
I answered B, because I thought since EVAL_BODY_BUFFERED is not a valid return type, it would throw some run time exception.
Correct answer:
Will not compile. EVAL_BODY_BUFFERED is not a valid return type for a tag that extends TagSupport. EVAL_BODY_INCLUDE or SKIP_BODY would be ok.
How can it check @ compile time???
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by amol re:
Assuming the rest of the code is valid,
which is true about this code?
public class TestTag extends TagSupport{
public int doStartTag(){
try{
JspWriter out=pageContext.getOut();
out.println("Customize");
}//try
catch(IOException ioex){}
return(EVAL_BODY_BUFFERED);
I answered B, because I thought since EVAL_BODY_BUFFERED is not a valid return type, it would throw some run time exception.
Correct answer:
Will not compile. EVAL_BODY_BUFFERED is not a valid return type for a tag that extends TagSupport. EVAL_BODY_INCLUDE or SKIP_BODY would be ok.
How can it check @ compile time???

Dear Amol,
In your TestTag.java, u have extended TagSupport class..
TagSupport implements IterationTag interface and provides implementations for each of the methods of the Tag and IterationTag interfaces.
EVAL_BODY_BUFFERED is the constant defined in interface BodyTag so ur file will not compile..
for ur java file to compile u have to extend BodyTagSupport class which implements the BodyTag class..
Thanks
Raj
 
Rajeev Ravindran
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A small correction
for ur java file to compile u have to extend BodyTagSupport class which implements the BodyTag class

for ur java file to compile u have to extend BodyTagSupport class which implements the BodyTag interface
Thanks
raj
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic