16AnonymousInner

16AnonymousInner - CS108, Stanford Winter 2012 Handout #16...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS108, Stanford Handout #16 Winter 2012 Young Anonymous Inner Class Handout by Nick Parlante Anonymous Inner Class (function pointer) An "anonymous" inner class is a type of inner class created on the fly with a quick-and-dirty syntax. Anonymous inner classes are convenient for creating small inner classes. An anonymous inner class can implement a superclass or interface, just like a regular inner class. Anonymous Inner Classes as shown below are essentially a way of making a cheap little function pointer objects to pass back to the client so they can invoke the code later on. As a matter of style, an anonymous inner class is appropriate for small inner classes. If the inner class involves longer code, then a regular named inner class is a better choice. When compiled, anonymous inner classes are given names like Outer$1, Outer$2 by the compiler. An anonymous inner class cannot have a constructor. It must rely on the default object initialization behavior. An anonymous inner class does not have a name, but it may be stored in a Superclass type pointer. The anonymous inner class has access to the outer class ivars, as usual for an inner class. The anonymous inner class does not have access to local stack vars from where it is declared, unless they
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

16AnonymousInner - CS108, Stanford Winter 2012 Handout #16...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online