嘿,我試圖在scala中以最好的方式編寫下面的代碼,如果有更好的方法,請幫助我!Scala傳遞類類型作爲參數
public final <T> T deserialize(String jsonString, Class<T> klass) {
try {
return objectMapper.readValue(jsonString, klass);
} catch (Exception e) {
LOG.error("Failed to deserialize {} to class {}, {}", jsonString, klass, e);
}
return null;
}
低於一個好的?
def deserialize[T: Manifest](value: String): T = {
mapper.readValue(value, typeReference[T])
}
'Manifest'已棄用。使用'TypeTag' – Falmarri