Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @NonNull
- private static Object stringToObject(@NonNull String string, @NonNull Class<?> clazz) {
- Class<?> wrapper = Array.get(Array.newInstance(clazz, 1), 0).getClass();
- try {
- return wrapper.getConstructor(String.class).newInstance(string);
- } catch (NoSuchMethodException e) {
- try {
- return wrapper.getConstructor(char.class).newInstance(string.charAt(0));
- } catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException | InstantiationException e1) {
- // cannot be
- }
- } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
- // cannot be
- }
- // cannot be
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement