Skip to content

Commit

Permalink
Remove deprecated method of newInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
kongleong86 committed Oct 2, 2023
1 parent cb2d794 commit 3c0bffa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void handleRequest(String request) {
private Command getCommand(String request) {
var commandClass = getCommandClass(request);
try {
return (Command) commandClass.newInstance();
return (Command) commandClass.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new ApplicationException(e);
}
Expand Down
5 changes: 3 additions & 2 deletions role-object/src/main/java/com/iluwatar/roleobject/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit 3c0bffa

Please sign in to comment.