Search code examples
javacompiler-errorschronicle-map

Can't close() map in ChronicleMap


According to the documentation, it is good practice to close https://github.com/OpenHFT/Chronicle-Map/blob/master/docs/CM_Tutorial.adoc#close-chroniclemap

I can't, for some reason:

Map<String, String> lexicalizationGraph = ChronicleMap
                .of(String.class, String.class)
                .name("lexicalizations-chronicle-map")
                .constantKeySizeBySample("bn:14271053n")
                .averageValue("average size of value")
                .entries(1_000_000_000L)
                .createPersistedTo(file);

and then later:

lexicalizationGraph.close();

It gives me the following error:

symbol:   method close()
  location: variable lexicalizationGraph of type java.util.Map<java.lang.String,java.lang.String>

How do I close it?


Solution

  • The close method is defined in ChronicleMap, not Map. To access it, you must define the variable as ChronicleMap (or explicitly cast it when you want to close(), but don't do that):

    ChronicleMap<String, String> lexicalizationGraph = ChronicleMap 
                    .of(String.class, String.class)
                    .name("lexicalizations-chronicle-map")
                    .constantKeySizeBySample("bn:14271053n")
                    .averageValue("average size of value")
                    .entries(1_000_000_000L)
                    .createPersistedTo(file);