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) {
Full Snippet Info
10
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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);
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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 
Full Snippet Info
9
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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);
        } 
    } 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 Field Questions & Answers:

See Code Examples for Java 8 Field Methods: