Skip to content

Commit

Permalink
DefaultFactory#create(Class<T>):
Browse files Browse the repository at this point in the history
Simplified normal instantiation
  • Loading branch information
rgoldberg authored and remkop committed Dec 15, 2021
1 parent 10ce657 commit 4e06c96
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -5505,12 +5505,10 @@ public <T> T create(Class<T> cls) throws Exception {
return cls.cast(new LinkedHashMap<Object, Object>());
}
}
Constructor<T> constructor = cls.getDeclaredConstructor();
try {
@SuppressWarnings("deprecation") // Class.newInstance is deprecated in Java 9
T result = cls.newInstance();
return result;
} catch (Exception ex) {
Constructor<T> constructor = cls.getDeclaredConstructor();
return constructor.newInstance();
} catch (IllegalAccessException ex) {
constructor.setAccessible(true);
return constructor.newInstance();
}
Expand Down

0 comments on commit 4e06c96

Please sign in to comment.