Reputation: 4992
I have created a simpe protocol and a type in Clojure:
(defprotocol Saving
(save [this] "saves to mongodb"))
;default implementation
(extend-type Object
Saving
(save [this] (encode this)))
(deftype NewsItem
[text date]
Saving)
However, when I try:
=> (def news-item (->NewsItem "Super News!!!" "today"))
and then:
=> (save news-item)
I get:
AbstractMethodError luminous_test.models.model.NewsItem.save()Ljava/lang/Object; luminous-test.models.model/eval2450 (NO_SOURCE_FILE:1)
What am I doing wrong? I feel like following the lines of creating a default protocol implementation but that's what I am getting...
Upvotes: 4
Views: 507
Reputation: 33637
Instead of
(deftype NewsItem
[text date]
Saving)
Just use:
(deftype NewsItem
[text date])
Upvotes: 5