refactor: Remove deprecated method of newInstance (#2594)

This commit is contained in:
kongleong86
2023-10-14 11:58:15 +01:00
committed by GitHub
parent 38d28870f2
commit 1bea90ed9c
2 changed files with 4 additions and 3 deletions
@@ -24,6 +24,7 @@
*/
package com.iluwatar.roleobject;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,8 +51,8 @@ public enum Role {
public <T extends CustomerRole> Optional<T> instance() {
var typeCst = this.typeCst;
try {
return (Optional<T>) Optional.of(typeCst.newInstance());
} catch (InstantiationException | IllegalAccessException e) {
return (Optional<T>) Optional.of(typeCst.getDeclaredConstructor().newInstance());
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
logger.error("error creating an object", e);
}
return Optional.empty();