當前位置: 首頁>>代碼示例>>Java>>正文


Java Field.getFloat方法代碼示例

本文整理匯總了Java中java.lang.reflect.Field.getFloat方法的典型用法代碼示例。如果您正苦於以下問題:Java Field.getFloat方法的具體用法?Java Field.getFloat怎麽用?Java Field.getFloat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.reflect.Field的用法示例。


在下文中一共展示了Field.getFloat方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLineSpacingAddAndLineSpacingMult

import java.lang.reflect.Field; //導入方法依賴的package包/類
private void getLineSpacingAddAndLineSpacingMult() {
    try {
        Field mSpacingAddField = TextView.class.getDeclaredField("mSpacingAdd");
        Field mSpacingMultField = TextView.class.getDeclaredField("mSpacingMult");
        mSpacingAddField.setAccessible(true);
        mSpacingMultField.setAccessible(true);
        mSpacingAdd = mSpacingAddField.getFloat(this);
        mSpacingMult = mSpacingMultField.getFloat(this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:hanks-zyh,項目名稱:LineHeightEditText,代碼行數:13,代碼來源:LineHeightEditText.java

示例2: getFloat

import java.lang.reflect.Field; //導入方法依賴的package包/類
public static float getFloat(Field field, Object source) {
	try {
		return field.getFloat(source);
	} catch (Exception e) {
		e.printStackTrace();
	}
	throw new RuntimeException("Error while getting field \"" + field.getName() + "\" from " + source + "!");
}
 
開發者ID:ProtocolSupport,項目名稱:ProtocolSupportPocketStuff,代碼行數:9,代碼來源:ReflectionUtils.java

示例3: getFloat

import java.lang.reflect.Field; //導入方法依賴的package包/類
public static float getFloat(Object instance, Field f)
{
    try {
        return f.getFloat(instance);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return 0;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:10,代碼來源:TypeAdapters.java

示例4: getField

import java.lang.reflect.Field; //導入方法依賴的package包/類
public static Object getField(Object instance, Field field) throws IllegalAccessException {
	if (UNSAFE != null) {
		if (int.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getInt(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (long.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getLong(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (double.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getDouble(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (void.class.equals(field.getType())) {
			return null;
		} else if (float.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getFloat(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (byte.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getByte(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (char.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getChar(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (boolean.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getBoolean(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else if (short.class.equals(field.getType())) {
			return ((sun.misc.Unsafe) UNSAFE).getShort(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		} else {
			return ((sun.misc.Unsafe) UNSAFE).getObject(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field));
		}
	} else { //Fallback if unsafe isn't available
		field.setAccessible(true);
		if (int.class.equals(field.getType())) {
			return field.getInt(instance);
		} else if (long.class.equals(field.getType())) {
			return field.getLong(instance);
		} else if (double.class.equals(field.getType())) {
			return field.getDouble(instance);
		} else if (void.class.equals(field.getType())) {
			return null;
		} else if (float.class.equals(field.getType())) {
			return field.getFloat(instance);
		} else if (byte.class.equals(field.getType())) {
			return field.getByte(instance);
		} else if (char.class.equals(field.getType())) {
			return field.getChar(instance);
		} else if (boolean.class.equals(field.getType())) {
			return field.getBoolean(instance);
		} else if (short.class.equals(field.getType())) {
			return field.getShort(instance);
		} else {
			return field.get(instance);
		}
	}
}
 
開發者ID:austinv11,項目名稱:ETF-Java,代碼行數:49,代碼來源:ReflectionUtils.java

示例5: equals

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * An introspection based equality predicate for SIPObjects.
 *@param other the other object to test against.
 */
public boolean equals(Object other) {
    if (!this.getClass().equals(other.getClass()))
        return false;
    SIPObject that = (SIPObject) other;
    Class myclass = this.getClass();
    Class hisclass = other.getClass();
    while (true) {
        Field[] fields = myclass.getDeclaredFields();
        if (!hisclass.equals(myclass))
            return false;
        Field[] hisfields = hisclass.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            Field f = fields[i];
            Field g = hisfields[i];
            // Only print protected and public members.
            int modifier = f.getModifiers();
            if ((modifier & Modifier.PRIVATE) == Modifier.PRIVATE)
                continue;
            Class fieldType = f.getType();
            String fieldName = f.getName();
            if (fieldName.compareTo("stringRepresentation") == 0) {
                continue;
            }
            if (fieldName.compareTo("indentation") == 0) {
                continue;
            }
            try {
                // Primitive fields are printed with type: value
                if (fieldType.isPrimitive()) {
                    String fname = fieldType.toString();
                    if (fname.compareTo("int") == 0) {
                        if (f.getInt(this) != g.getInt(that))
                            return false;
                    } else if (fname.compareTo("short") == 0) {
                        if (f.getShort(this) != g.getShort(that))
                            return false;
                    } else if (fname.compareTo("char") == 0) {
                        if (f.getChar(this) != g.getChar(that))
                            return false;
                    } else if (fname.compareTo("long") == 0) {
                        if (f.getLong(this) != g.getLong(that))
                            return false;
                    } else if (fname.compareTo("boolean") == 0) {
                        if (f.getBoolean(this) != g.getBoolean(that))
                            return false;
                    } else if (fname.compareTo("double") == 0) {
                        if (f.getDouble(this) != g.getDouble(that))
                            return false;
                    } else if (fname.compareTo("float") == 0) {
                        if (f.getFloat(this) != g.getFloat(that))
                            return false;
                    }
                } else if (g.get(that) == f.get(this))
                    continue;
                else if (f.get(this) == null && g.get(that) != null)
                    return false;
                else if (g.get(that) == null && f.get(this) != null)
                    return false;
                else if (!f.get(this).equals(g.get(that)))
                    return false;
            } catch (IllegalAccessException ex1) {
                System.out.println("accessed field " + fieldName);
                System.out.println("modifier  " + modifier);
                System.out.println("modifier.private  " + Modifier.PRIVATE);
                InternalErrorHandler.handleException(ex1);
            }
        }
        if (myclass.equals(SIPObject.class))
            break;
        else {
            myclass = myclass.getSuperclass();
            hisclass = hisclass.getSuperclass();
        }
    }
    return true;
}
 
開發者ID:YunlongYang,項目名稱:LightSIP,代碼行數:81,代碼來源:SIPObject.java


注:本文中的java.lang.reflect.Field.getFloat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。