On Tue, Apr 18, 2017 at 2:14 PM, Emmanuel Bourg <ebo...@apache.org> wrote:

> Le 18/04/2017 à 23:06, Gary Gregory a écrit :
>
> > This use case does not make sense to me. If an object is immutable, then
> it
> > is thread safe. If you want to include an asynchronous external resource
> as
> > part of your object, then the object might not be in fact, immutable.
> > Speaking of a specific use case would be better.
>
> What about something like a FileOutputStream?


A JRE FileOutputStream (Oracle Java 8) is not immutable.


> The object fields could be
> final (the file descriptor never changes), but the write methods can't
> be safely called concurrently.
>
> Another example would be an interface to a remote service. The stub
> could be immutable and contain the URL of the remote service, but the
> operations couldn't be called by multiple threads.
>

I'd like to see a real example before we talk about abstract arguments and
counter-arguments, which will never end ;-)

I mean, OK you have a service, with a final URL and no other state. So the
"invoke" method creates all the resources it needs, so that's thread-safe.
If you want a not thread-safe design, then you save these resources in
instance variables for reuse. You'd allocate those in the ctor to make them
final in order to keep the object immutable. Then we get into the usual
discussion that no class is final unless all of its ivars are final. And if
each ivar is also an Object, IT must be immutable to call the composite
immutable.

All of this to say, that having final non-primitive instance variables does
not make a class immutable (transitively). So maybe we need to allow for
that level of documentation IMMUTABLE vs. IMMUTABLE_TRANSITIVE.

Gary


>
> Emmanuel Bourg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
>
>


-- 
E-Mail: garydgreg...@gmail.com | ggreg...@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Reply via email to