trampoline : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

trampoline
Every anonymous (or named) inner class you create for an EventListener consumes about 3K overhead. There are several ways to reduce that overhead. One is to use a single Listener object and get it to field events for several components. Another is to use trampolines. Trampolines use reflection to save the overhead of inner classes. You may say, But isn’t that slow? No because the overhead of a single reflection call per button press is negligible. Even the slowest machine can do over a hundred such calls a second. The key is a generic ActionListener class. You instantiate one such object per ActionListener, though they are all the same class. You use it like You still have an Object per ActionListener overhead, but that overhead is tiny, only about 16 bytes, compared with 3K per anonymous inner class. You can use the same technique for other sorts of Listener. The beauty is you only have to write the GenericActionListener once. It can then handle all your ActionListener needs in any application.

I would not recommend trampolines for unsigned Applets. They will likely either trigger or will some day trigger a security exeception with their Reflection use.

Learning More

Oracle’s Javadoc on ActionListener interface : available:

This page is posted
on the web at:

http://mindprod.com/jgloss/trampoline.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\trampoline.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[18.224.0.25]
You are visitor number