immutability

Jackson JSON, Immutable Classes, and Interfaces

跟風遠走 提交于 2019-12-03 15:25:49
问题 I am playing with the Jackson examples and am having some trouble getting deserialization to work with immutable classes and interfaces. Below is my code: package com.art.starter.jackson_starter; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import org.codehaus.jackson.JsonGenerationException; import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; /** * Hello world! * */ public class App { public static void

Why does CouchDB use an append-only B+ tree and not a HAMT

老子叫甜甜 提交于 2019-12-03 14:46:39
I'm reading up on datastructures, especially immutable ones like the append-only B+ tree used in CouchDB and the Hash array mapped trie used in Clojure and some other functional programming languages. The main reason datastructures that work well in memory might not work well on disk appears to be time spent on disk seeks due to fragmentation, as with a normal binary tree. However, HAMT is also very shallow, so doesn't require any more seeks than a B tree. Another suggested reason is that deletions from a array mapped trie are more expensive tha from a B tree. This is based on the assumption

Serializing immutable java classes to actionscript with LCDS

隐身守侯 提交于 2019-12-03 13:52:53
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-serialization-proxy/ This is how I originally wrote my java class, expecting livecycle to call the

How to create default constructor for immutable class

ε祈祈猫儿з 提交于 2019-12-03 13:06:42
I like to make my objects immutable based on this article (Why objects must be immutable) . However, I am trying to parse an object using Jackson Object Mapper. I was initially getting JsonMappingException: No suitable constructor found for type [simple type, class ]: cannot instantiate from JSON object. I could fix it as mentioned here , by providing a default constructor and making my fields non-final. import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; @AllArgsConstructor //

Automapper and immutability

自闭症网瘾萝莉.ら 提交于 2019-12-03 13:03:33
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? 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 AutoMapper to go from view to domain, you're now locked in to an anemic domain model, whether you've

Constant Object vs Immutable Object

怎甘沉沦 提交于 2019-12-03 12:45:20
问题 Can I use the term "Constant Object" in the place of the term "Immutable Object"? Though I get the feeling that Immutable for an Object is what Constant is for a variable, I am not sure if this terminology is accepted. Please help me understand. Thanks, Karthick S. 回答1: In fact, in Java the term constant has no defined meaning. It occurs in the JLS only in the larger term compile time constant expression , which is an expression which can (and must) be calculated by the compiler instead of at

Why no immutable double linked list in Scala collections?

感情迁移 提交于 2019-12-03 12:20:48
Looking at this question, where the questioner is interested in the first and last instances of some element in a List , it seems a more efficient solution would be to use a DoubleLinkedList that could search backwards from the end of the list. However there is only one implementation in the collections API and it's mutable. Why is there no immutable version? Because you would have to copy the whole list each time you want to make a change. With a normal linked list, you can at least prepend to the list without having to copy everything. And if you do want to copy everything on every change,

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

南楼画角 提交于 2019-12-03 11:59:46
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 me Cannot convert value of type '() -> FlattenCollection<[[String : AnyObject]]>' to specified type '

Unit testing for object immutability

雨燕双飞 提交于 2019-12-03 11:54:44
I want to make sure that a given group of objects is immutable. I was thinking about something along the lines of: check if every field is private final check if class is final check for mutable members So I guess my question is: is 3. possible ? I can check recursively whether every member of a class has its fields private final , but this is not enough since a class can have e method named getHaha(param) which adds the given param to an array for instance. So is there a good way to check if an object is immutable or is it even possible ? Thanks, If you generate your data model and all its

If delegates are immutable, why can I do things like x += y?

限于喜欢 提交于 2019-12-03 11:53:00
问题 Reading C# In Depth, 2nd edition , section 2.1.2 on combining and removing delegates. The subsection title states that "delegates are immutable" and that "nothing about them can be changed." In the next paragraph, though, it talks about using constructs like x += y; where x and y are variables of compatible delegate types. Didn't I just change x ? Or does the immutability part deal with when x is disposed of when I do this (i.e., immediately)? 回答1: That's like doing: string x = "x"; string y