Doesn't java have kinda-sorta union types now? Like, you could declare
a method as:
public <T extends Closeable & Serializable> void serializeAndClose(T
thing) {...}
It seems like marker interfaces are no longer necessary for this sort
of thing. Likewise in Clojure, instead of having a
CloseableSerializable protocol (gross!), you can write
(defn closeable-and-serializable? [x]
(every? #(instance? % x) [Closeable Serializable]))
;; use satisfies? instead if you have protocols
The problem with "union interfaces" has always been that you're happy
to serializeAndClose anyone who's both Closeable and Serializable, but
the type system (before Java 1.5) didn't let you express that; instead
clients had to participate in your imaginary private interface. I
don't think it's a good idea to carry this antipattern over to
Clojure.
On Oct 4, 8:23 pm, hgreen <[email protected]> wrote:
> "Marker interface" is the right idea (and I did in fact look it up in
> Wikipedia last night :-)), but I was trying to avoid saying that. What my
> stuff is doing is arguably a little different: a Java analogy would be
> something like defining a new interface that's a composite of several other
> interfaces. This feels slightly (maybe very slightly) more elevated than
> simply annotating a class, which is more or less how I'd say marker
> interfaces tend to be used. It all comes to the same thing in the end,
> though. Point is, zero-method protocols are occasionally a useful tool.
>
> -- Howard
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en