Search code examples
javavalue-typechronicle-map

Java: Does Chronicle Map support different value classes?


I usually create a new Chronicle Map using a ChronicleMapBuilder like so:

ChronicleMapBuilder<SomeKey, MyImplClass> builder
        = ChronicleMapBuilder.of(SomeKey.class, MyImplClass.class);

ChronicleMap<SomeKey, MyImplClass> map
        = builder.constantKeySizeBySample(someKey)
                 .averageValue(someValue)
                 .entries(myCollection.size())
                 .createPersistedTo(myFile);

Does Chronicle Map support the storage of instances of different value classes and if so, how do I build that map?

For example:

ChronicleMapBuilder<SomeKey, MyInterfaceThatHasManyDifferentImplementations> builder
        = // .. now what?

Basically, I have only one key class - a LocalDate. But this date can (or at least, I want it to) be mapped to different implementations of a common interface. I consider myself lucky to have a common interface, but if it is possible to build a Chronicle Map even without a common interface, please advise.

I am sorry I do not currently have the ability to test Chronicle Map's support for different value classes nor am I able to find this documented in any shape or form on the Internet.


Solution

  • ChronicleMapBuilder#of takes two Class arguments. In the worst case, you can use Object.class was your value class (the second argument), and store whatever values you want in the map.