Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Now that we’ve seen the soft underbelly of protocols in
Example 6-7, we should mention the
convenience functions for introspecting protocols:
extenders, extends?,
and satisfies?, which collectively
provide a supported API for answering common questions about protocols and
their relationships with types.
extendersReturns the classes that have been extended to a given
protocol. For example, after going through the examples involving
the Measurable protocol in the
last section, we can see which types participate in that
protocol:
(extenders Measurable) ;= (user.BorderedButton user.Button)
This is the equivalent of asking, “Which classes implement
some Java interface x?” Note
that, because types can be extended to satisfy protocols
at any point at runtime, these results are only
true for the point in time when a protocol is queried via extenders.