trampoline : Java Glossary

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:

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/trampoline.html J:\mindprod\jgloss\trampoline.html
logofeedback Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email If you want your message kept confidential, not considered for posting, please explicitly specify that.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.214]
You are visitor number 8,195.