I want to replace my lambda expression with a method reference. Following is my code snippet.
@FunctionalInterface
interface MessageProcessor<T, E extends Exception> {
void process(T t) throws E;
}
and my class is
public class MessageHandler {
public static Map<String, MessageProcessor<JsonElement, Exception>> map = new HashMap<>();
map.put("create_key" , (jsonElement) -> MessageUtil.processCreate(jsonElement));
map.put("update_key" , (jsonElement) -> MessageUtil.processUpdate(jsonElement));
map.put("delete_key" , (jsonElement) -> MessageUtil.processDelete(jsonElement));
}
and my utility methods are
public static void processCreate(JsonElement jsonElement) throws Exception {
// create logic
}
public static void processUpdate(JsonElement jsonElement) throws Exception {
// update logic
}
public static void processDelete(JsonElement jsonElement) throws Exception {
// delete logic
}
Now I want to replace the lambda expression with a method reference. How can I replace?