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


Java Field類代碼示例

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


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

示例1: createAndroidNClassLoader

import java.lang.reflect.Field; //導入依賴的package包/類
private static AndroidNClassLoader createAndroidNClassLoader(PathClassLoader originalClassLoader, Application application) throws Exception {
    //let all element ""
    final AndroidNClassLoader androidNClassLoader = new AndroidNClassLoader("",  originalClassLoader, application);
    final Field pathListField = ShareReflectUtil.findField(originalClassLoader, "pathList");
    final Object originPathList = pathListField.get(originalClassLoader);

    // To avoid 'dex file register with multiple classloader' exception on Android O, we must keep old
    // dexPathList in original classloader so that after the newly loaded base dex was bound to
    // AndroidNClassLoader we can still load class in base dex from original classloader.

    Object newPathList = recreateDexPathList(originPathList, androidNClassLoader);

    // Update new classloader's pathList.
    pathListField.set(androidNClassLoader, newPathList);

    return androidNClassLoader;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:AndroidNClassLoader.java

示例2: getStatments

import java.lang.reflect.Field; //導入依賴的package包/類
protected static Map<String, SQLStmt> getStatments(Procedure proc) {
    Class<? extends Procedure> c = proc.getClass();
    Map<String, SQLStmt> stmts = new HashMap<String, SQLStmt>();
    for (Field f : c.getDeclaredFields()) {
        int modifiers = f.getModifiers();
        if (Modifier.isTransient(modifiers) == false &&
            Modifier.isPublic(modifiers) == true &&
            Modifier.isStatic(modifiers) == false) {
            try {
                Object o = f.get(proc);
                if (o instanceof SQLStmt) {
                    stmts.put(f.getName(), (SQLStmt)o);
                }
            } catch (Exception ex) {
                throw new RuntimeException("Failed to retrieve " + f + " from " + c.getSimpleName(), ex);
            }
        }
    } // FOR
    return (stmts);
}
 
開發者ID:faclc4,項目名稱:HTAPBench,代碼行數:21,代碼來源:Procedure.java

示例3: scan

import java.lang.reflect.Field; //導入依賴的package包/類
public PostProcessor[] scan(final Object instance) {
    return FluentIterable
            .from(ReflectionUtils.getDeclaredFields(instance.getClass(), true))
            .filter(new Predicate<Field>() {
                @Override
                public boolean apply(Field input) {
                    return input.isAnnotationPresent(Random.PostProcessor.class)
                            && PostProcessor.class.isAssignableFrom(input.getType());
                }
            })
            .transform(new Function<Field, PostProcessor>() {
                @Override
                public PostProcessor apply(Field field) {
                    try {
                        if (!ReflectionUtils.makeFieldAccessible(field)) {
                            return null;
                        }
                        return (PostProcessor) field.get(instance);
                    } catch (IllegalAccessException e) {
                        throw new RandomitoException(e);
                    }
                }
            })
            .filter(Predicates.<PostProcessor>notNull())
            .toArray(PostProcessor.class);
}
 
開發者ID:randomito,項目名稱:randomito-all,代碼行數:27,代碼來源:AnnotationPostProcessorScanner.java

示例4: scanField

import java.lang.reflect.Field; //導入依賴的package包/類
@Override
protected void scanField(Field field, long offset) {
    Class<?> type = field.getType();
    if (VALUE_CLASS.isAssignableFrom(type) && !CONSTANT_VALUE_CLASS.isAssignableFrom(type)) {
        assert !Modifier.isFinal(field.getModifiers()) : "Value field must not be declared final because it is modified by register allocator: " + field;
        OperandModeAnnotation annotation = getOperandModeAnnotation(field);
        assert annotation != null : "Field must have operand mode annotation: " + field;
        EnumSet<OperandFlag> flags = getFlags(field);
        assert verifyFlags(field, type, flags);
        annotation.values.add(new ValueFieldInfo(offset, field.getName(), type, field.getDeclaringClass(), flags));
        annotation.directCount++;
    } else if (VALUE_ARRAY_CLASS.isAssignableFrom(type)) {
        OperandModeAnnotation annotation = getOperandModeAnnotation(field);
        assert annotation != null : "Field must have operand mode annotation: " + field;
        EnumSet<OperandFlag> flags = getFlags(field);
        assert verifyFlags(field, type.getComponentType(), flags);
        annotation.values.add(new ValueFieldInfo(offset, field.getName(), type, field.getDeclaringClass(), flags));
    } else {
        assert getOperandModeAnnotation(field) == null : "Field must not have operand mode annotation: " + field;
        assert field.getAnnotation(LIRInstruction.State.class) == null : "Field must not have state annotation: " + field;
        super.scanField(field, offset);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:LIRIntrospection.java

示例5: findFieldsNotAnnotatedWith

import java.lang.reflect.Field; //導入依賴的package包/類
public static SaveField[] findFieldsNotAnnotatedWith(Class<? extends Annotation> annotation, Class<?>... classes) {
    List<SaveField> fields = new LinkedList<>();
    int i = 0;

    for (Class<?> clazz : classes) {
        for (Field f : clazz.getDeclaredFields()) {
            if (!f.isAnnotationPresent(annotation)) {
                fields.add(new SaveField(f, i));
            }
            i++;
        }
        i = 0;
    }

    return fields.toArray(new SaveField[fields.size()]);
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:17,代碼來源:ReflectionHelper.java

示例6: startEmbeddedActivity

import java.lang.reflect.Field; //導入依賴的package包/類
public EmbeddedActivityRecord startEmbeddedActivity(String bundleName) throws Exception{
    EmbeddedActivityRecord activityRecord = new EmbeddedActivityRecord();
    activityRecord.id = "embedded_"+mParent.getClass().getSimpleName();
    Field mThemeResourceF = AndroidHack.findField(mParent,"mThemeResource");
    int mThemeResource = (Integer)mThemeResourceF.get(mParent);
    Intent intent = new Intent();
    intent.setClassName(mParent,EmbeddedActivity.class.getName());
    intent.putExtra("themeId",mThemeResource);
    intent.putExtra("bundleName",bundleName);
    ActivityInfo info = intent.resolveActivityInfo(mParent.getPackageManager(), PackageManager.GET_ACTIVITIES);
    activityRecord.activity = (EmbeddedActivity) ActivityThread_startActivityNow.invoke(AndroidHack.getActivityThread(),
            mParent, activityRecord.id, intent, info, activityRecord.activity, null, null);
    activityRecord.activityInfo = info;
    return activityRecord;
}
 
開發者ID:alibaba,項目名稱:atlas,代碼行數:16,代碼來源:RemoteActivityManager.java

示例7: getField

import java.lang.reflect.Field; //導入依賴的package包/類
/**
 * Get class field
 *
 * @param fieldName Field's name
 * @param type Field's type class
 * @param <V> Field's type
 * @return {@link FieldWrapper} object or empty, if field wasn't found
 */
@Contract("null, null -> fail")
@SuppressWarnings("unchecked")
public <V> Optional<FieldWrapper<V>> getField(String fieldName, Class<V> type) {
    /* Check arguments */
    if(fieldName == null) throw new IllegalStateException("Field name shouldn't be null!");
    if(type == null) throw new IllegalStateException("Field type shouldn't be null!");

    /* Try to find cached field */
    FieldInfo fieldInfo = new FieldInfo(fieldName, type);

    /* Get field */
    Integer found = FIELD_INDEX.get(fieldInfo);
    Field[] field = new Field[] { found != null ? FIELD_CACHE.get(found) : null };
    field[0] = field[0] != null ? field[0] : findDeclaredField(fieldName, type);
    if(field[0] == null) return Optional.empty();

    /* Wrap field */
    return Optional.of((FieldWrapper<V>)FIELDWRAPPER_CACHE.computeIfAbsent(found,
            k -> MethodHandleFieldWrapper.of(this, field[0], type)));
}
 
開發者ID:mikroskeem,項目名稱:Shuriken,代碼行數:29,代碼來源:ClassWrapper.java

示例8: getProperties

import java.lang.reflect.Field; //導入依賴的package包/類
@Override
public List<Property> getProperties() {
    if (proxy.properties == null) {
        proxy.properties = new ArrayList<>();
        proxy.propertyAccessors = new HashMap<>();
        for (Field f : getAccessibleFields()) {
            ODataProperty annotation = f.getAnnotation(ODataProperty.class);
            if (annotation != null) {
                String name = annotation.name();
                RealAccessors<JpaOlingoEntity> accessors = new RealAccessors<>(this, f);
                proxy.properties.add(new Property(null, name, annotation.valueType(), accessors.get(this)));
                proxy.propertyAccessors.put(name, accessors);
            }
        }
    }
    return proxy.properties;
}
 
開發者ID:mat3e,項目名稱:olingo-jpa,代碼行數:18,代碼來源:JpaOlingoEntity.java

示例9: merge

import java.lang.reflect.Field; //導入依賴的package包/類
/**
 * 合並pipeline參數設置
 */
public void merge(PipelineParameter pipelineParameter) {
    try {
        Field[] fields = this.getClass().getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            Field field = fields[i];
            // Skip static and final fields.
            if (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) {
                continue;
            }

            ReflectionUtils.makeAccessible(field);
            Object srcValue = field.get(pipelineParameter);
            if (srcValue != null) { // 忽略null值
                field.set(this, srcValue);
            }
        }
    } catch (Exception e) {
        // ignore
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:24,代碼來源:PipelineParameter.java

示例10: getIdTable

import java.lang.reflect.Field; //導入依賴的package包/類
protected Map<Integer, String> getIdTable(@RTypes String resName) throws IllegalAccessException, ClassNotFoundException {
    // R資源類全稱
    String rClassName = mPackageName + ".R$" + resName;

    if (mResourceCache.hasIdTableCache(rClassName)) {
        return mResourceCache.getIdTableCache(rClassName);
    }

    Class                stringRClass = Class.forName(rClassName);
    Field[]              fields       = stringRClass.getDeclaredFields();
    Map<Integer, String> idTable      = new HashMap<>();
    for (Field field : fields) {
        field.setAccessible(true);

        int    id   = (int) field.get(null);
        String name = field.getName();

        idTable.put(id, name);
    }

    mResourceCache.cacheIdTable(rClassName, idTable);

    return idTable;
}
 
開發者ID:kkmike999,項目名稱:YuiHatano,代碼行數:25,代碼來源:ShadowResources.java

示例11: getDomainIDClass

import java.lang.reflect.Field; //導入依賴的package包/類
/**
 * 獲取實體類ID Class
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
public static Class<? extends Serializable> getDomainIDClass(Class<? extends BaseDomain> clazz){
	/**
	 * 如果是聯合主鍵實體類則返回domainID,因為聯合主鍵類必須實現getDomainID()方法
	 */
	IdClass annotation = clazz.getAnnotation(IdClass.class);
	if (annotation != null) {
		return annotation.value();
	}
	try {
		Field f = ReflectUtil.getDeclaredField(clazz, getDomainIDName(clazz));
		if (f != null) {
			return (Class<? extends Serializable>) f.getType();
		}
	} catch (Exception e) {
		e.printStackTrace();
		throw createFindIdException(clazz, e);
	}  
	throw createIDNotfoundException(clazz);
}
 
開發者ID:battlesteed,項目名稱:hibernateMaster,代碼行數:26,代碼來源:DomainUtil.java

示例12: init

import java.lang.reflect.Field; //導入依賴的package包/類
@PostConstruct
public void init() throws
        IllegalAccessException, NoSuchMethodException, InvocationTargetException {

    Collection<SiteOption> siteOptionKeyValues = siteOptionRepository.findAll();

    Map<String, Object> options = new Hashtable<>();
    for (SiteOption siteOption : siteOptionKeyValues) {
        options.put(siteOption.getName(), siteOption.getValue());
    }
    for (String key : options.keySet()) {
        for (Field f : this.getClass().getDeclaredFields()) {
            if (f.getName().toUpperCase().equals(key.toUpperCase())) {
                setSiteOptionProperty(key, options.get(key));
            }
        }
    }
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:19,代碼來源:SiteOptions.java

示例13: closeBlocking

import java.lang.reflect.Field; //導入依賴的package包/類
@Override
public void closeBlocking() throws InterruptedException {
    super.closeBlocking();
    try {
        Field channelField = this.getClass().getSuperclass().getDeclaredField("channel");
        channelField.setAccessible(true);
        SocketChannel channel = (SocketChannel) channelField.get(this);
        if (channel != null && channel.isOpen()) {
            Socket socket = channel.socket();
            if (socket != null)
                    socket.close();
        }
    }
    catch (Exception ex) {
        System.out.println("Exception in Websocket close hack.");
        ex.printStackTrace();
    }
}
 
開發者ID:lazyparser,項目名稱:xbot_head,代碼行數:19,代碼來源:ROSBridgeWebSocketClient.java

示例14: getHiddenFields

import java.lang.reflect.Field; //導入依賴的package包/類
public static Set<Field> getHiddenFields(final Class<?> clazz) {
	final Field[] fields = clazz.getDeclaredFields();
	final Set<Field> declaredFieldSet = CollectionUtils.arrayToSet(fields);
	final Set<Field> ret = new HashSet<>();

	Class<?> currentClass = clazz.getSuperclass();

	while (currentClass != null) {
		final Field[] superFields = currentClass.getDeclaredFields();

		for (Field superField : superFields) {
			final Field match = getMatch(declaredFieldSet, superField);

			if (!Modifier.isPrivate(superField.getModifiers()) && !Modifier.isStatic(superField.getModifiers())
					&& match != null) {
				ret.add(match);
			}
		}
		currentClass = currentClass.getSuperclass();
	}

	return ret;
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:24,代碼來源:Reflections.java

示例15: setField

import java.lang.reflect.Field; //導入依賴的package包/類
/**
 * Sets the field, bypassing scope restriction.
 *
 * @param subject Object where the field belongs
 * @param fieldName name of the field to set
 * @param value value to set to the field.
 * @param <T> subject type
 * @param <U> value type
 * @throws TestUtilsException if there are reflection errors while setting
 * the field
 */
public static <T, U> void setField(T subject, String fieldName, U value)
        throws TestUtilsException {
    @SuppressWarnings("unchecked")
    Class clazz = subject.getClass();
    try {
        while (clazz != null) {
            try {
                Field field = clazz.getDeclaredField(fieldName);
                field.setAccessible(true);
                field.set(subject, value);
                break;
            } catch (NoSuchFieldException ex) {
                if (clazz == clazz.getSuperclass()) {
                    break;
                }
                clazz = clazz.getSuperclass();
            }
        }
    } catch (SecurityException | IllegalArgumentException |
             IllegalAccessException e) {
        throw new TestUtilsException("setField failed", e);
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:35,代碼來源:TestUtils.java


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