当前位置: 首页>>代码示例>>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;未经允许,请勿转载。