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


Java Field.get方法代碼示例

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


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

示例1: query

import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
public void query(Object object, Field field, Collection<String> queries)
	throws IllegalAccessException, InstantiationException
{
	Class<?> type = field.getType();
	if( ConfigurationProperties.class.isAssignableFrom(type) )
	{
		ConfigurationProperties fobject = (ConfigurationProperties) field.get(object);
		if( fobject == null )
		{
			fobject = (ConfigurationProperties) type.newInstance();
			field.set(object, fobject);
		}
		queries.addAll(PropertyBeanFactory.getSelect(fobject));
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:17,代碼來源:BeanPropertySerialiser.java

示例2: getFieldValue

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * 通過反射, 獲取obj對象的 指定成員變量的值
 */
public static Object getFieldValue(Object obj, String fieldName) {
    if (obj == null || TextUtils.isEmpty(fieldName)) {
        return null;
    }

    Class<?> clazz = obj.getClass();
    while (clazz != Object.class) {
        try {
            Field field = clazz.getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(obj);
        } catch (Exception e) {
            L.e("錯誤:" + e.getMessage());
        }
        clazz = clazz.getSuperclass();
    }
    return null;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:22,代碼來源:Reflect.java

示例3: showPopupDialog

import java.lang.reflect.Field; //導入方法依賴的package包/類
public void showPopupDialog(Dialog dialog) {
    try {
        Field field = dialog.getClass().getDeclaredField("mAlert");
        field.setAccessible(true);
        Object obj = field.get(dialog);
        field = obj.getClass().getDeclaredField("mHandler");
        field.setAccessible(true);
        field.set(obj, new ButtonHandler(dialog));
    } catch (SecurityException e) {
        LOG.e(TAG, "set button handler failed(SecurityException)", e);
    } catch (NoSuchFieldException e2) {
        LOG.e(TAG, "set button handler failed(NoSuchFieldException)", e2);
    } catch (IllegalArgumentException e3) {
        LOG.e(TAG, "set button handler failed(IllegalArgumentException)", e3);
    } catch (IllegalAccessException e4) {
        LOG.e(TAG, "set button handler failed(IllegalAccessException)", e4);
    } catch (Throwable t) {
        LOG.e(TAG, "set button handler failed(Throwable)", t);
    }
    dialog.show();
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:22,代碼來源:BasicActivity.java

示例4: getResourceId

import java.lang.reflect.Field; //導入方法依賴的package包/類
private static Object getResourceId(Context context, String name, String type) {
    try {
        for (Class childClass : Class.forName(context.getPackageName() + ".R").getClasses()) {
            if (childClass.getSimpleName().equals(type)) {
                for (Field field : childClass.getFields()) {
                    if (field.getName().equals(name)) {
                        return field.get(null);
                    }
                }
                continue;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:18,代碼來源:ResourceUtil.java

示例5: ModManager

import java.lang.reflect.Field; //導入方法依賴的package包/類
public ModManager()
{
	try
	{
		for(Field field : ModManager.class.getFields())
			if(field.getName().endsWith("Mod"))
			{
				Mod mod = (Mod)field.get(this);
				mods.put(mod.getName(), mod);
				mod.initSettings();
			}
		
	}catch(Exception e)
	{
		throw new ReportedException(
			CrashReport.makeCrashReport(e, "Initializing Wurst mods"));
	}
}
 
開發者ID:Wurst-Imperium,項目名稱:Wurst-MC-1.12,代碼行數:19,代碼來源:ModManager.java

示例6: install

import java.lang.reflect.Field; //導入方法依賴的package包/類
private static void install(ClassLoader classLoader, File folder)  throws Throwable {
    Field pathListField = ShareReflectUtil.findField(classLoader, "pathList");
    Object dexPathList = pathListField.get(classLoader);

    Field nativeLibraryDirectories = ShareReflectUtil.findField(dexPathList, "nativeLibraryDirectories");

    List<File> libDirs = (List<File>) nativeLibraryDirectories.get(dexPathList);
    libDirs.add(0, folder);
    Field systemNativeLibraryDirectories =
            ShareReflectUtil.findField(dexPathList, "systemNativeLibraryDirectories");
    List<File> systemLibDirs = (List<File>) systemNativeLibraryDirectories.get(dexPathList);
    Method makePathElements =
            ShareReflectUtil.findMethod(dexPathList, "makePathElements", List.class);
    libDirs.addAll(systemLibDirs);
    Object[] elements = (Object[]) makePathElements.
            invoke(dexPathList, libDirs);
    Field nativeLibraryPathElements = ShareReflectUtil.findField(dexPathList, "nativeLibraryPathElements");
    nativeLibraryPathElements.setAccessible(true);
    nativeLibraryPathElements.set(dexPathList, elements);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:TinkerLoadLibrary.java

示例7: getStaticIntegerField

import java.lang.reflect.Field; //導入方法依賴的package包/類
static Integer getStaticIntegerField(Class clazz, String variableName)
        throws NoSuchFieldException, IllegalAccessException {
    Field intField = clazz.getDeclaredField(variableName);
    intField.setAccessible(true);
    Integer value = (Integer) intField.get(null);
    return value;
}
 
開發者ID:fjoglar,項目名稱:android-dev-challenge,代碼行數:8,代碼來源:TestUtilities.java

示例8: get

import java.lang.reflect.Field; //導入方法依賴的package包/類
public Object get(String varName) throws Exception {
  Field f;
  try {
    f = this.getClass().getDeclaredField(varName);
  } catch (NoSuchFieldException fex) {
    f = this.getClass().getSuperclass().getDeclaredField(varName);
  }
  Object o = f.get(this);
  return o;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:11,代碼來源:DomainObject.java

示例9: retrieveOldFieldValue

import java.lang.reflect.Field; //導入方法依賴的package包/類
private static Object retrieveOldFieldValue(String className, String fieldName) {
 	try {
  	Class<?> tmp  = Class.forName(className);	
Field field = tmp.getField(fieldName);
field.setAccessible(true);
return field.get(Class.forName(className));
 	}catch(Exception ex) {
 		ex.printStackTrace();
 		return null;
 	}
 }
 
開發者ID:srasthofer,項目名稱:FuzzDroid,代碼行數:12,代碼來源:Hooker.java

示例10: startActivityFromFragment

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * 這裏的做法是支持Fragment中調用startActivityForResult特性
 * <p>
 * 由於衛士的插件需要hook住XXX-Activity的startActivity和startActivityForResult接口
 * 但早期版本的support-v4在startActivityFromFragment中直接調用了super.startActivityForResult, 因此這裏還需要hook住這個點
 * 但新版的support-v4中Fragment最終的調用鏈還是會走到本XXX-Activity的startActivityForResult接口,因此不需要適配startActivityFromFragment(Fragment fragment, Intent intent, int requestCode, @Nullable Bundle options)接口
 *
 * @param fragment
 * @param intent
 * @param requestCode
 */
@Override
public void startActivityFromFragment(Fragment fragment, Intent intent, int requestCode) {
    if (requestCode == -1) {
        startActivityForResult(intent, -1);
    } else if ((requestCode & -65536) != 0) {
        throw new IllegalArgumentException("Can only use lower 16 bits for requestCode");
    } else {
        int newRequestCode = -1;
        try {
            Field f = Fragment.class.getDeclaredField("mIndex");
            boolean acc = f.isAccessible();
            if (!acc) {
                f.setAccessible(true);
            }
            Object o = f.get(fragment);
            if (!acc) {
                f.setAccessible(acc);
            }
            int index = (Integer) o;
            newRequestCode = ((index + 1) << 16) + (requestCode & '\uffff');
        } catch (Throwable e) {
            // Do Noting
        }
        startActivityForResult(intent, newRequestCode);
    }
}
 
開發者ID:wangyupeng1-iri,項目名稱:springreplugin,代碼行數:38,代碼來源:PluginAppCompatActivity.java

示例11: injectDependencies

import java.lang.reflect.Field; //導入方法依賴的package包/類
@Override
protected void injectDependencies(TestContext testContext) throws Exception {
    super.injectDependencies(testContext);
    /**
     * 獲取測試類 & fields
     */
    Object bean = testContext.getTestInstance();
    List<Field> fields = getDeclaredFields(bean);
    if (CollectionUtils.isEmpty(fields)) {
        return;
    }
    /**
     * 如果測試類中, 被測試對象含有mockito的@InjectMocks注解,且 被測試對象被事務攔截器攔截 則 用原始對象代替
     */
    for (Field field : fields) {
        InjectMocks injectMocks = field.getAnnotation(InjectMocks.class);
        if (injectMocks == null) {
            continue;
        }
        field.setAccessible(true);
        Object proxy = field.get(bean);
        if (AopUtils.isAopProxy(proxy)) {
            // 替換對象
            Object target = ((Advised) proxy).getTargetSource().getTarget();
            field.set(bean, target);
        }
    }
}
 
開發者ID:warlock-china,項目名稱:wisp,代碼行數:29,代碼來源:UnitTestDependencyInjectionTestExecutionListener.java

示例12: ensureChildHelper

import java.lang.reflect.Field; //導入方法依賴的package包/類
void ensureChildHelper() {
    try {
        if (mInnerChildHelper == null) {
            mInnerChildHelper = mChildHelperField.get(mLayoutManager);
            if (mInnerChildHelper == null) return;

            Class<?> helperClz = mInnerChildHelper.getClass();
            mHideMethod = helperClz.getDeclaredMethod("hide", View.class);
            mHideMethod.setAccessible(true);
            mFindHiddenNonRemovedViewMethod = helperClz.getDeclaredMethod("findHiddenNonRemovedView", int.class/*, int.class*/);
            mFindHiddenNonRemovedViewMethod.setAccessible(true);
            mIsHideMethod = helperClz.getDeclaredMethod("isHidden", View.class);
            mIsHideMethod.setAccessible(true);

            Field bucketField = helperClz.getDeclaredField("mBucket");
            bucketField.setAccessible(true);

            mInnerBucket = bucketField.get(mInnerChildHelper);
            mClearMethod = mInnerBucket.getClass().getDeclaredMethod("clear", int.class);
            mClearMethod.setAccessible(true);

            mHiddenViewField = helperClz.getDeclaredField("mHiddenViews");
            mHiddenViewField.setAccessible(true);
            mInnerHiddenView = (List) mHiddenViewField.get(mInnerChildHelper);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:31,代碼來源:RLinearLayoutManager.java

示例13: getFieldVal

import java.lang.reflect.Field; //導入方法依賴的package包/類
public static Object getFieldVal(Object o,String fieldName){
try {
	Field field = getDeclaredField(o, fieldName);
	field.setAccessible(true); 
       return field.get(o); 
} catch (Exception ex) {
	log.error(ex.getMessage(), ex);
}
return null;
  }
 
開發者ID:xiaomin0322,項目名稱:marathon-auth-plugin,代碼行數:11,代碼來源:AuthUtil.java

示例14: assertNotSerializable

import java.lang.reflect.Field; //導入方法依賴的package包/類
/**
 * Verify the class cannot be deserialized from a handcoded stream.
 * Fail if the deserialization does <em>not</em> throw an Exception.
 * @param serClass the class to embed in the handcoded stream
 * @throws Exception if an unexpected condition occurs
 */
protected static void assertNotSerializable(Class<?> serClass) throws Exception {
    Field field = serClass.getDeclaredField("serialVersionUID");
    field.setAccessible(true);
    long serVer = (Long) field.get(null);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (DataOutputStream out = new DataOutputStream(baos)) {
        out.writeShort(ObjectStreamConstants.STREAM_MAGIC);
        out.writeShort(ObjectStreamConstants.STREAM_VERSION);
        out.writeByte(ObjectStreamConstants.TC_OBJECT);
        out.writeByte(ObjectStreamConstants.TC_CLASSDESC);
        out.writeUTF(serClass.getName());
        out.writeLong(serVer);
        out.writeByte(ObjectStreamConstants.SC_SERIALIZABLE);   // Flags ObjectStreamConstants
        out.writeShort(0);  // number of fields
        out.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA);
        out.writeByte(ObjectStreamConstants.TC_NULL);  // no superclasses
    }

    byte[] bytes = baos.toByteArray();

    try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream in = new ObjectInputStream(bis)) {
        Object o = in.readObject();
    } catch (Exception ioe) {
        // Expected exception
        return;
    }
    fail("Class should not be deserializable " + serClass.getName());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:36,代碼來源:AbstractTCKTest.java

示例15: getValue

import java.lang.reflect.Field; //導入方法依賴的package包/類
private static <T> T getValue(String name, Object instance) {
	try {
		Field f = LineNumberChangeRulerColumn.class.getDeclaredField(name);
		f.setAccessible(true);
		return (T) f.get(instance);
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
開發者ID:angelozerr,項目名稱:codelens-eclipse,代碼行數:11,代碼來源:LineNumberChangeRulerColumnPatch.java


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