Java 8 Field - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Field class.

This code example shows how to use the following methods:setAccessible, get
 
	private static int getImageViewFieldValue(Object object, String fieldName) {
		int value = 0;
		try { 
			Field field = ImageView.class.getDeclaredField(fieldName);
			field.setAccessible(true);
			int fieldValue = (Integer) field.get(object);
			if (fieldValue > 0 && fieldValue < Integer.MAX_VALUE) {
				value = fieldValue;
			} 
		} catch (Exception e) {
			L.e(e);
		} 
		return value;
	} 
 
	@Override 
	public boolean setImageDrawable(Drawable drawable) {
		ImageView imageView = imageViewRef.get();
		if (imageView != null) {
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setAccessible
		} 
 
		try { 
			cdBackgroundStateColorField = cdBackgroundStateField.getType()
					.getDeclaredField(COLOR_DRAWABLE_USE_COLOR_VAR);
			cdBackgroundStateColorField.setAccessible(true);
		} catch (Exception e) {
			Log.e(TAG,
					"Reflection failed while trying to determine background color of view.", 
					e);
			cdBackgroundStateColorField = null;
			return; 
		} 
 
	} 
 
	private int getColorFromColorDrawable(ColorDrawable colorDrawable)
	{ 
		if (IS_HONEYCOMB_OR_GREATER) {
			return getColorFromColorDrawableHC(colorDrawable);
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isAccessible, setAccessible, getName
    public void injectField (Field field, Object injectable)
    {            
        try 
        { 
            //validateInjection(field, injectable); 
            boolean accessibility = field.isAccessible();
            field.setAccessible(true);
            field.set(injectable, lookupInjectedValue());
            field.setAccessible(accessibility);
        } 
        catch (Exception e)
        { 
            Log.warn(e);
            throw new IllegalStateException("Inject failed for field "+field.getName());
        } 
    } 
     
    /** 
     * Inject value from jndi into a setter method of an instance 
     * @param method 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isAccessible, setAccessible, get, getModifiers, set
		mockHttpServletRequest.setServerName("www.liferay.com");
 
		Field field = ReflectionUtil.getDeclaredField(
			CookieKeys.class, "_SESSION_COOKIE_DOMAIN"); 
 
		Object value = field.get(null);
 
		try { 
			field.set(null, "www.example.com");
 
			String domain = CookieKeys.getDomain(mockHttpServletRequest);
 
			Assert.assertEquals("www.example.com", domain);
		} 
		finally { 
			field.set(null, value);
		} 
	} 
 
	@Test

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:get
            return read() == null; 
    } 
 
    public Object read() {
        try { 
            return field.get(target);
        } catch (Exception e) {
            throw new MockitoException("Cannot read state from field: " + field + ", on instance: " + target);
        } 
    } 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setAccessible, get
        Field cleanerField;
        long fieldOffset = -1;
        if (PlatformDependent0.hasUnsafe()) { 
            try { 
                cleanerField = direct.getClass().getDeclaredField("cleaner");
                cleanerField.setAccessible(true);
                Cleaner cleaner = (Cleaner) cleanerField.get(direct);
                cleaner.clean();
                fieldOffset = PlatformDependent0.objectFieldOffset(cleanerField);
            } catch (Throwable t) {
                // We don't have ByteBuffer.cleaner(). 
                fieldOffset = -1;
            } 
        } 
        logger.debug("java.nio.ByteBuffer.cleaner(): {}", fieldOffset != -1? "available" : "unavailable");
        CLEANER_FIELD_OFFSET = fieldOffset;
 
        // free buffer if possible 
        freeDirectBuffer(direct);
    } 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getDeclaringClass, getName, getType
 
            try { 
 
                final Resources resources = application.getResources();
                final int id = getId(resources,annotation);
                final Class<?> t = field.getType();
 
                if (String.class.isAssignableFrom(t)) {
                    value = resources.getString(id);
                } else if (boolean.class.isAssignableFrom(t) || Boolean.class.isAssignableFrom(t)) {
                    value = resources.getBoolean(id);
                } else if (ColorStateList.class.isAssignableFrom(t)  ) {
                    value = resources.getColorStateList(id);
                } else if (int.class.isAssignableFrom(t) || Integer.class.isAssignableFrom(t)) {
                    value = resources.getInteger(id);
                } else if (Drawable.class.isAssignableFrom(t)) {
                    value = resources.getDrawable(id);
                } else if (String[].class.isAssignableFrom(t)) {
                    value = resources.getStringArray(id);
                } else if (int[].class.isAssignableFrom(t) || Integer[].class.isAssignableFrom(t)) {

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setAccessible, get
public class ReflectionUtil { 
 
    public static Object getFieldValue(Object object, String fieldName) {
        try { 
            Field field = object.getClass().getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(object);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } 
    } 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setAccessible, get, getName
	} 
 
	@Override 
	public Object getFieldValue(Object object, Field field) {
		try { 
			field.setAccessible(true);
			return field.get(object);
		} catch (IllegalArgumentException e) {
			throw new InfinitumRuntimeException("Unable to access field '" + field.getName() + "' for object of type '"
					+ object.getClass().getName() + "'.", e);
		} catch (IllegalAccessException e) {
			throw new InfinitumRuntimeException("Unable to access field '" + field.getName() + "' for object of type '"
					+ object.getClass().getName() + "'.", e);
		} 
	} 
 
	@Override 
	public Object invokeMethod(Object receiver, Method method, Object... args) {
		try { 
			method.setAccessible(true);
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setAccessible, get, set
public class JndiLocatorDelegateTests { 
 
	@Test
	public void isDefaultJndiEnvironmentAvailableFalse() throws Exception {
		Field builderField = NamingManager.class.getDeclaredField("initctx_factory_builder");
		builderField.setAccessible(true);
		Object oldBuilder = builderField.get(null);
		builderField.set(null, null);
 
		try { 
			assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable(), equalTo(false)); 
		} 
		finally { 
			builderField.set(null, oldBuilder);
		} 
	} 
 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 Field Questions & Answers:

See Code Examples for Java 8 Field Methods: