1

When reading the description for javax.servlet.jsp.tagext I came across a strange usage of the syntax ClassName.this.methodName() in the section Generated Simple Tag Handler (MySimpleTag.java), specifically in the MySimpleTag.doTag() method.

public class MySimpleTag
    extends javax.servlet.jsp.tagext.SimpleTagSupport
[...]
{
    protected JspContext jspContext;
    public void setJspContext( JspContext ctx ) {
        super.setJspContext( ctx );
        // Step T.2 - A JspContext wrapper is created.
        // (Implementation of wrapper not shown).
        this.jspContext = new utils.JspContextWrapper( ctx );
    }
    public JspContext getJspContext() {
        // Step T.2 - Calling getJspContext() must return the 
        // wrapped JspContext.
        return this.jspContext;
    }

    public void doTag() throws JspException {
        java.lang.Object jspValue;
        JspContext jspContext = getJspContext();
        JspContext _jsp_parentContext = 
            SimpleTagSupport.this.getJspContext();
        [...]
    }
    [...]
}

I thought ClassName.this was only to be used within non-static inner classes that need access to the containing class instance.

And indeed, if I try to reproduce this in a simple example where a derived class calls a base class method with BaseClass.this.someMethod(), I get a compiler error:

error: not an enclosing class: BaseClass
    return Base.this.someMethod();
               ^

So does that mean the code for MySimpleTag.doTag() in the API documentation has a syntax error? Was the line actually supposed to be this?

JspContext _jsp_parentContext = 
            super.getJspContext();
Community
  • 1
  • 1
mxxk
  • 9,514
  • 5
  • 38
  • 46

1 Answers1

0

As @EJP points out, it's probably a documentation bug. The compile-time error makes it pretty clear the ClassName.this syntax is illegal outside of a non-static inner class.

mxxk
  • 9,514
  • 5
  • 38
  • 46