Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Clojure Polymorphism

You're reading from   Clojure Polymorphism Leverage Clojure's polymorphic tools to develop your applications

Arrow left icon
Product type Paperback
Published in Nov 2019
Publisher
ISBN-13 9781838982362
Length 56 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Paul Stadig Paul Stadig
Author Profile Icon Paul Stadig
Paul Stadig
Arrow right icon
View More author details
Toc

Miscellaneous JVM Considerations

Because of the way protocols are implemented on the JVM, there are a couple of considerations to keep in mind, one about performance and one about semantics, and they would each push you in different directions.

Performance Gotcha

The performance of Clojure protocols is a bit nuanced. A Clojure protocol generates a Java interface, a protocol, and some protocol functions. The protocol functions will dispatch through the Java interface if the type of the first argument implements the interface; otherwise, it will dispatch through the protocol's dispatch table.

There are two ways to implement a protocol in Clojure:

1 (defrecord S3Storage

2     [access-key secret-key]

3   proto/IStorage

4   ...)

Or:

1 (defrecord S3Storage

2     [access-key secret-key])

3

4 (extend-protocol IStorage

5   S3Storage

6 ...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime