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


Java Field.setChar方法代碼示例

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


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

示例1: read

import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public void read(Bundle bundle, Object to, StateField field) throws IllegalAccessException {
    Field propertyField = field.getField();
    propertyField.setAccessible(true);
    propertyField.setChar(to,bundle.getChar(field.getBundleKey()));

}
 
開發者ID:leobert-lan,項目名稱:MagicBox,代碼行數:8,代碼來源:CharReader.java

示例2: setField

import java.lang.reflect.Field; //導入方法依賴的package包/類
public static void setField(Object instance, Field field, Object value) throws IllegalAccessException {
	if (value == null && field.getType().isPrimitive()) {
		return;
	}
	
	if (UNSAFE != null) {
		if (int.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putInt(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (int) value);
		} else if (long.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putLong(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (long) value);
		} else if (double.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putDouble(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (double) value);
		} else if (void.class.equals(field.getType())) {
		
		} else if (float.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putFloat(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (float) value);
		} else if (byte.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putByte(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (byte) value);
		} else if (char.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putChar(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (char) value);
		} else if (boolean.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putBoolean(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (boolean) value);
		} else if (short.class.equals(field.getType())) {
			((sun.misc.Unsafe) UNSAFE).putShort(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), (short) value);
		} else {
			((sun.misc.Unsafe) UNSAFE).putObject(instance, ((sun.misc.Unsafe) UNSAFE).objectFieldOffset(field), value);
		}
	} else { //Fallback if unsafe isn't available
		field.setAccessible(true);
		if (int.class.equals(field.getType())) {
			field.setInt(instance, (int) value);
		} else if (long.class.equals(field.getType())) {
			field.setLong(instance, (long) value);
		} else if (double.class.equals(field.getType())) {
			field.setDouble(instance, (double) value);
		} else if (void.class.equals(field.getType())) {
			
		} else if (float.class.equals(field.getType())) {
			field.setFloat(instance, (float) value);
		} else if (byte.class.equals(field.getType())) {
			field.setByte(instance, (byte) value);
		} else if (char.class.equals(field.getType())) {
			field.setChar(instance, (char) value);
		} else if (boolean.class.equals(field.getType())) {
			field.setBoolean(instance, (boolean) value);
		} else if (short.class.equals(field.getType())) {
			field.setShort(instance, (short) value);
		} else {
			field.set(instance, value);
		}
	}
}
 
開發者ID:austinv11,項目名稱:ETF-Java,代碼行數:53,代碼來源:ReflectionUtils.java

示例3: decodeInternal

import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public <T> void decodeInternal(BsonReader reader, T instance, Field field) throws IllegalAccessException {
    field.setChar(instance, (char) reader.readInt32());
}
 
開發者ID:axelspringer,項目名稱:polymorphia,代碼行數:5,代碼來源:MappedField.java


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