Object (final Element element, final String attributeName, final Class valueClass) { final String str = getRequiredString(element, attributeName); try { final Method method = valueClass.getMethod("valueOf", String.class); return method.invoke(null, str); } catch (NumberFormatException e) { throw new IllegalArgumentException("attribute '" + attributeName + "' is not a proper float: " + str); } catch (Exception e) { throw new RuntimeException(e); } }