Is the following correct?

The only way to define *multiple* mutable instance variables/fields for a 
class visible in Java is by using deftype with :volatile-mutable or 
:unsynchronized-mutable.
The only way to inherit from a concrete Java class is by using gen-class or 
proxy.  gen-class allows a single mutable field using :state and :init.
Thus there is no way to define a class that both inherits from a concrete 
class and defines more than one new instance variable.

I believe these statements are correct, but gen-class is complex and 
deftype use has some nuances, so I want to make sure I haven't missed 
something.

I know that I can use gen-class's state variable to hold multiple mutable 
structures by putting e.g. atoms inside of a map or record stored in the 
state variable, or by storing a deftype instance with mutable fields in the 
state variable.

(Context: I'm getting a meaningful performance boost by replacing atoms in 
a map or a record in a gen-class state variable, with deftype with 
:volatile-mutable in a gen-class state variable.  I keep wondering whether 
my gen-class class really needs to delegate to a deftype structure.  This 
is for an application that needs to extend one or more Java classes.  I 
know that :volatile-mutable and :unsynchronized-mutable are intended to be 
used only by experts.  I'm not an expert.  I've asked a question on 
StackOverflow 
<http://stackoverflow.com/questions/30472496/risks-of-volatile-mutable-fields-in-single-threaded-contexts>
 
about whether the particular way that I'm using :volatile-mutable, i.e. 
solely in single-threaded application, is safe.  Feel free to comment there 
or here on that issue, as well as on my main question above.)

Thanks.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to