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


Java Field.getByte方法代碼示例

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


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

示例1: getVal

import java.lang.reflect.Field; //導入方法依賴的package包/類
int getVal(Field f) {
    try {
        if (f.getType() == int.class) {
            return f.getInt(this);
        } else if (f.getType() == short.class) {
            return (int)f.getShort(this);
        } else if (f.getType() == byte.class) {
            return (int)f.getByte(this);
        } else if (f.getType() == long.class) {
            return (int)f.getLong(this);
        }
    } catch(IllegalAccessException iae) {
        throw new RuntimeException("Setting fields failed");
    }
    throw new RuntimeException("unexpected field type");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:TestInstanceCloneUtils.java

示例2: getByte

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

示例3: 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

示例4: getIdLength

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Get id length property by reflection.
 *
 * @param entry Password Entry instance
 * @return id length
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
private byte getIdLength(PasswordPinEntry entry) throws NoSuchFieldException, IllegalAccessException {
    Field f = TestUtils.getField(entry.getClass(), "idLength");
    if (f == null)
        throw new NoSuchFieldException();
    return f.getByte(entry);
}
 
開發者ID:bertrandmartel,項目名稱:javacard-tutorial,代碼行數:15,代碼來源:PasswordEntryTest.java

示例5: getUsernameLength

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Get username length property by reflection.
 *
 * @param entry Password entry instance
 * @return username length
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
private byte getUsernameLength(PasswordPinEntry entry) throws NoSuchFieldException, IllegalAccessException {
    Field f = TestUtils.getField(entry.getClass(), "userNameLength");
    if (f == null)
        throw new NoSuchFieldException();
    return f.getByte(entry);
}
 
開發者ID:bertrandmartel,項目名稱:javacard-tutorial,代碼行數:15,代碼來源:PasswordEntryTest.java

示例6: getPasswordLength

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Get password length property by reflection.
 *
 * @param entry Password entry instance
 * @return password length
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
private byte getPasswordLength(PasswordPinEntry entry) throws NoSuchFieldException, IllegalAccessException {
    Field f = TestUtils.getField(entry.getClass(), "passwordLength");
    if (f == null)
        throw new NoSuchFieldException();
    return f.getByte(entry);
}
 
開發者ID:bertrandmartel,項目名稱:javacard-tutorial,代碼行數:15,代碼來源:PasswordEntryTest.java

示例7: getIdLength

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Get id length property by reflection.
 *
 * @param entry Password Entry instance
 * @return id length
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
private byte getIdLength(PasswordEntry entry) throws NoSuchFieldException, IllegalAccessException {
    Field f = TestUtils.getField(entry.getClass(), "idLength");
    if (f == null)
        throw new NoSuchFieldException();
    return f.getByte(entry);
}
 
開發者ID:bertrandmartel,項目名稱:javacard-tutorial,代碼行數:15,代碼來源:PasswordEntryTest.java

示例8: getUsernameLength

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Get username length property by reflection.
 *
 * @param entry Password entry instance
 * @return username length
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
private byte getUsernameLength(PasswordEntry entry) throws NoSuchFieldException, IllegalAccessException {
    Field f = TestUtils.getField(entry.getClass(), "userNameLength");
    if (f == null)
        throw new NoSuchFieldException();
    return f.getByte(entry);
}
 
開發者ID:bertrandmartel,項目名稱:javacard-tutorial,代碼行數:15,代碼來源:PasswordEntryTest.java

示例9: getPasswordLength

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Get password length property by reflection.
 *
 * @param entry Password entry instance
 * @return password length
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
private byte getPasswordLength(PasswordEntry entry) throws NoSuchFieldException, IllegalAccessException {
    Field f = TestUtils.getField(entry.getClass(), "passwordLength");
    if (f == null)
        throw new NoSuchFieldException();
    return f.getByte(entry);
}
 
開發者ID:bertrandmartel,項目名稱:javacard-tutorial,代碼行數:15,代碼來源:PasswordEntryTest.java


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