Code example for Field

Methods: setAccessiblegetType

0
	public FieldReplacer(Class<? extends Instance> clazz, String fieldName, Class<Type> requiredType) {
		try { 
			this.requiredType = requiredType;
			field = clazz.getDeclaredField(fieldName);
 
			field.setAccessible(true);
			if (!requiredType.isAssignableFrom(field.getType())) {
				throw new ExceptionInInitializerError("Field of wrong type");
			} 
		} catch (NoSuchFieldException e) {
			throw new ExceptionInInitializerError(e);
		} 
	} 
 
	public Type get(Instance instance) {
		try { 
			return this.requiredType.cast(field.get(instance));
		} catch (IllegalAccessException e) {
			throw new Error(e);
		} 
Connect your IDE to all the code out there  Get Codota for Java