trampoline : Java Glossary

go to home page T words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
index page for letter ⇒ punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (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 this:
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

Sun’s Javadoc on the ActionListener interface class : available:

CMP homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.61] The information on this page is for non-military use only.
You are visitor number 4,812. Military use includes use by defence contractors.
You can get a fresh 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