Immutable or not immutable?

后端 未结 6 974
离开以前
离开以前 2020-12-08 23:06

Ok, as I understand it, immutable types are inherently thread safe or so I\'ve read in various places and I think I understand why it is so. If the inner state of a

6条回答
  •  余生分开走
    2020-12-08 23:36

    Using your code, let's say i do this:

    ImmutableList mylist = new ImmutableList();
    
    mylist.Add(1); 
    

    ... your code, posted on StackOverflow, causes a StackOverflow-Exception. There are quite a few sensible ways to create thread save collection, copying collections (at least trying to) and calling them immutable, a lot, doesn't quite do the trick.

    Eric Lippert posted a link that might be very worth reading.

提交回复
热议问题