boolean (String settingName, Object object, Object value) { try { Field field = object.getClass().getField(settingName); field.set(object, value); return true; } catch (IllegalAccessException e) { throw new IllegalArgumentException(String.format("Can't set property with the name %s in object %s", settingName, object)); } catch (NoSuchFieldException e) { // Do nothing - will try other variants } return false; }