I have a Map like Map idMap = new Hashhap<String, AnyClass>; where the key is a specific Id (we deal with many ids), let's call it MyEntityId.
So for readability and in order to avoid problems in the usage of this map, I would like to transform it in a nicer: Map idMap = new Hashmap<MyEntityId, AnyClass>
now, the implementation of MyEntityId, using lombock, would just be:
@Data
@AllArgumentsConstructor
public class MyEntityId {
private String id;
}
The thing is that now every time i have a String representing MyEntityId i have to transform it new MyEntityId(myString) and doing so, i am losing the advantages of the internal representation of the String. So if before for the String "123abc" i had only one object in the JVM, now i have as many objects as the new MyEntityId(id) constructor is invoked.
How can i solve this?
HashMap<MyEntityId, AnyClass>nicer thanHashMap<String, AnyClass>?MyCaseClass(theString). Maybe a type alias is what you mean?type MyEntityId = String