Code example for Field

Methods: setAccessiblegetAnnotationgetDeclaringClassgetNamegetTypeset

		Object value = null;
		final String servieName =;
		value = context.getSystemService(servieName);
		if (value == null && field.getAnnotation(Nullable.class) == null) {
			throw new NullPointerException(
							"Can't inject null value into %s.%s when field is not @Nullable", 
							field.getDeclaringClass(), field.getName()));
		try { 
			field.set(instance, value);
		catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		catch (IllegalArgumentException f) {
			throw new IllegalArgumentException(String.format(
					"Can't assign %s value %s to %s field %s", 
					value != null ? value.getClass() : "(null)", value, field
							.getType(), field.getName()));
Stop searching for code, let great code find you!  Add Codota to your java IDE