immutability

Serializing immutable java classes to actionscript with LCDS

杀马特。学长 韩版系。学妹 提交于 2019-12-21 04:49:10
问题 I've got a complex object which is being managed by the LCDS DataServices data management and being created/updated etc using custom assemblers. The vast majority of the object hierarchy is being serialized/deserialized correctly but I've hit a stumbling block when it comes to serializing immutable java classes. In a java only world I would use the java writeReplace and readResolve methods as this excellent blog describes: http://lingpipe-blog.com/2009/08/10/serializing-immutable-singletons

Automapper and immutability

烂漫一生 提交于 2019-12-21 04:08:41
问题 Is it possible to use AutoMapper with Immutable types? For example my Domain type is immutable and I want to map my view type to this. I believe it is not but just want this confirmed. Also as it is best practice to have your domain types immutable, what is the best practice when mapping your view types to domain types? 回答1: I typically do the mapping from view types to domain types by hand, as I'll typically be working through a more complex interface, using methods and so on. If you use

How do I “append” to an immutable dictionary in Swift?

吃可爱长大的小学妹 提交于 2019-12-21 04:03:22
问题 In Scala, the + (k -> v) operator on immutable.Map returns a new immutable.Map with the contents of the original, plus the new key/value pair. Similarly, in C#, ImmutableDictionary.add(k, v) returns a new, updated ImmutableDictionary . In Swift, however, Dictionary appears only to have the mutating updateValue(v, forKey: k) function and the mutating [k:v] operator. I thought maybe I could play some trick with flatten() , but no luck: let updated = [original, [newKey: newValue]].flatten() gets

Is a lock required with a lazy initialization on a deeply immutable type?

北战南征 提交于 2019-12-21 03:58:08
问题 If I have a deeply immutable type (all members are readonly and if they are reference type members, then they also refer to objects that are deeply immutable). I would like to implement a lazy initialized property on the type, like this: private ReadOnlyCollection<SomeImmutableType> m_PropName = null; public ReadOnlyCollection<SomeImmutableType> PropName { get { if(null == m_PropName) { ReadOnlyCollection<SomeImmutableType> temp = /* do lazy init */; m_PropName = temp; } return m_PropName; }

What does immutable and readonly mean in C#?

与世无争的帅哥 提交于 2019-12-21 03:34:40
问题 Is it correct that it is not possible to change the value of an immutable object? I have two scenarios regarding readonly that I want to understand: What if I have a collection and mark it as readonly , like the following. Can I still call _items.Add ? private readonly ICollection<MyItem> _items; And also for the following variable, if later on I call _metadata.Change which will change the internal values of a couple member variable in the Metadata instance. Is _metadata still immutable?

Disadvantages of Immutable objects

孤街醉人 提交于 2019-12-21 02:48:17
问题 I know that Immutable objects offer several advantages over mutable objects like they are easier to reason about than mutable ones, they do not have complex state spaces that change over time, we can pass them around freely, they make safe hash table keys etc etc.So my question is what are the disadvantages of immutable objects?? 回答1: Quoting from Effective Java : The only real disadvantage of immutable classes is that they require a separate object for each distinct value. Creating these

Scala immutable objects and traits with val fields

醉酒当歌 提交于 2019-12-20 19:42:29
问题 I would like to construct my domain model using immutable objects only. But I also want to use traits with val fields and move some functionality to traits. Please look at the following example: trait Versionable { val version = 0 def incrementVersion = copy(version=version+1) } Unfortunatelly such code doesn't work - copy method is unknown for trait Versionable. I think that it would be nice to have copy method generated for every trait and class. Such method should create shallow copy of

Is it possible to have immutable fields in Hibernate/JPA?

北慕城南 提交于 2019-12-20 17:32:49
问题 In our application, we need to have fields that are assignable only once. At first we thought of encapsulating the fields and making the setters private. However, some questions arouse: Without a public setter, is Hibernate still able to map the field from the database? Can I strip out the setter and make the field mutable only in the entity constructor? Finally, is there any standard JPA way to make a field immutable? Thanks in advance. 回答1: Ad. 1: I believe JPA uses plain private fields for

Scala: collecting updates/changes of immutable state

人盡茶涼 提交于 2019-12-20 17:31:31
问题 I'm currently trying to apply a more functional programming style to a project involving low-level (LWJGL-based) GUI development. Obviously, in such a case it is necessary to carry around a lot of state, which is mutable in the current version. My goal is to eventually have a completely immutable state, in order to avoid state changes as side effect. I studied scalaz's lenses and state monads for awhile, but my main concern remains: All these techniques rely on copy-on-write. Since my state

Possible to have immutable JPA entities?

夙愿已清 提交于 2019-12-20 11:51:17
问题 In our hibernate project, the entities are coded using the java beans pattern. There's quite a few spots in our code where someone has forgotten a to set a mutator and we get an exception due to a NOT NULL field. Is anyone using a builder to construct their entities or making them immutable? I'm trying to find an effective pattern that is not in the style of the java beans pattern. Thanks 回答1: If you make your beans immutable then you have to use field level access and this comes with its own