I would like to make Map values resolvement lazy, so was thinking about providing a Supplier with a toString function. But below code does not compile:
A default method cannot override a method from java.lang.Object
Anyone an idea how to solve this in a neat way?
@FunctionalInterface
private static interface ToStringSupplier extends Supplier<String>
{
default public String toString() {
return get();
}
}
The reason I want this is that my consumers (which are in another repository) first can update their code:
From:
String value = (Strint)map.get(key);
To:
String value = map.get(key).toString();
After which I can change the implementation to a lazy approach:
From:
String value = expensiveCalculation();
map.put(key,value);
To:
Supplier<String> supplier () -> expensiveCalculation();
map.put(key, supplier);