Advertisement
GenuineSounds

Untitled

Jan 14th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. public <T> void set(final String name, final T value) throws UnhandledTypeException {
  2.     Class<Data<?>> clazz = TypeSystem.getTypeSystem().lookupDataClass(value);
  3.     try {
  4.         Constructor[] consts = clazz.getDeclaredConstructors();
  5.         for (Constructor constructor : consts)
  6.             System.out.println(constructor);
  7.         Constructor constructor = clazz.getConstructor(value.getClass());
  8.         values.put(name, (Data) constructor.newInstance(value));
  9.     } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
  10.         throw new UnhandledTypeException("Unhandled Data type: There is no corresponding Data type for the class " + value.getClass().getSimpleName());
  11.     }
  12. }
  13.  
  14. // Console Output:
  15. // public ninja.genuine.conjure.data.primitive.DataDouble()
  16. // public ninja.genuine.conjure.data.primitive.DataDouble(double)
  17. // ninja.genuine.conjure.UnhandledTypeException: Unhandled Data type: There is no corresponding Data type for the class Double
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement