Вызывающий:
Код: Выделить всё
public Features findFeatureById(BigDecimal id) {
return mixedCacheService.get(FEATURE, id.toString(), new MixedCacheService.Func(() -> featuresDao.selectById(id)));
}
Код: Выделить всё
public T get(@NotNull CacheBaseConstants cacheBaseConstants, @NotNull String key, @NotNull Supplier getter) {
String value = get(cacheBaseConstants, key);
if ("".equals(value)) {
return null;
}
// How can I get T.class here?
return Optional.ofNullable(value)
.map(o -> JSON.parseObject(value, T.class))
.orElseGet(() -> put(cacheBaseConstants, key, getter));
}
Код: Выделить всё
public static class Func extends TypeReference {
private Supplier supplier;
public Func(Supplier supplier) {
super();
this.supplier = supplier;
}
public T get() {
return supplier.get();
}
}
Я хотел бы знать, как успешно получить класс для . Будем очень признательны за любые идеи и предложения!
Подробнее здесь: https://stackoverflow.com/questions/790 ... od-in-java
Мобильная версия