Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

6. Datatypes and Protocols > Protocol Introspection

Protocol Introspection

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.

extenders

Returns 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.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial