Hi,
Am 22.12.2010 um 11:15 schrieb Mark Engelberg:
> Are there any examples available of creating a compiled
> class/interface with deftype and defprotocol, and using these from
> Java?
Protocols also define an interface which can be implemented by classes. For
deftype this happens when you specify the methods inline in the deftype
definition. Then you can call the method directly on the object as you would do
with any other java method. However this does not work for types which use
extend to extend the protocol to the type. Here you still have to go through
the protocol functions.
An example should look like this:
(ns some.name.space)
(defprotocol SomeProtocol
(foo [this]))
(deftype SomeType
[a b]
SomeProtocol
(foo [this] (str a b)))
Then in Java:
import some.name.space.SomeType;
…
SomeType st = new SomeType("some a", "and a b");
…
st.foo();
Not tested, though.
Sincerely
Meikel
--
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