If I have an anonymous inner class object like this (where Foo is an interface):
Foo foo = new Foo(){
@Override
public String hello(Object dummyArg){
return "hello, world.";
}
};
and I try to call Foo.hello
from a jsp like this:
${foo.hello('blah')}
it throws:
javax.el.MethodNotFoundException: Unable to find method [hello] with [1] parameters
but if there are no parameters:
Bar bar = new bar(){
@Override
public String hello(){
return "hello, world.";
}
};
...
${bar.hello()}
it works fine. Why?
This is not a duplicate of 7121303. I'm asking specifically about anonymous inner classes. With an instance of a regular class, it works with any number of parameters.
Object = new Example() { public void display() { System. out. println("Anonymous class overrides the method display()."); } }; Here, an object of the anonymous class is created dynamically when we need to override the display() method.
Explanation: D is correct. It defines an anonymous inner class instance, which also means it creates an instance of that new anonymous class at the same time. The anonymous class is an implementer of the Runnable interface, so it must override the run() method of Runnable.
It is an inner class without a name and for which only a single object is created. An anonymous inner class can be useful when making an instance of an object with certain “extras” such as overriding methods of a class or interface, without having to actually subclass a class.
18) Which of the following is true about the anonymous inner class? Explanation: Anonymous inner classes are the same as the local classes except that they don't have any name. The main use of it is to override methods of classes or interfaces.
Possibly, you need to create EL function though which you can pass parameter. (http://blog.idleworx.com/2010/04/custom-tags-and-custom-el-functions-in.html)
the support for passing method arguments and invoking non-getter methods was introduced in EL 2.2 . Enable EL 2.2 on tomcat (http://code2inspire.wordpress.com/2010/11/05/how-to-enable-el-2-2-on-tomcat-6/)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With