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


Java ReflectionFactory類代碼示例

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


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

示例1: asNMSIngredient

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
public RecipeItemStack asNMSIngredient() {
		try {
		    //not usable with java 9
//			RecipeItemStack recipeItemStackInjected = (RecipeItemStack) unsafe.allocateInstance(recipeItemStackInjectedClass);
//			ReflectionUtil.setDeclaredFieldValue(recipeItemStackInjected, "predicate", tester);
//			ReflectionUtil.setFinalFieldValue(recipeItemStackInjected, "choices", new ItemStack[0]);
//			return recipeItemStackInjected;

		    //not usable to to illegal access exception
//			Constructor<? extends RecipeItemStack> constructor = recipeItemStackInjectedClass.getConstructor(Predicate.class);
//			RecipeItemStack recipeItemStackInjected = constructor.newInstance(tester);
//			return recipeItemstackInjected;
		    
		    Constructor<? extends RecipeItemStack> constructor = (Constructor<? extends RecipeItemStack>) ReflectionFactory.getReflectionFactory()
		            .newConstructorForSerialization(recipeItemStackInjectedClass, Object.class.getConstructor()); //TODO generates NPE?
		    RecipeItemStack recipeItemStackInjected = constructor.newInstance();
		    ReflectionUtil.setDeclaredFieldValue(recipeItemStackInjected, "predicate", tester);
		    ReflectionUtil.setFinalFieldValue(recipeItemStackInjected, "choices", new ItemStack[0]);
		    return recipeItemStackInjected;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
 
開發者ID:Jannyboy11,項目名稱:CustomRecipes,代碼行數:24,代碼來源:InjectedIngredient.java

示例2: setFailsafeFieldValue

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
public static void setFailsafeFieldValue(Field field, Object target, Object value)
        throws NoSuchFieldException, IllegalAccessException {

    // let's make the field accessible
    field.setAccessible(true);

    // next we change the modifier in the Field instance to
    // not be final anymore, thus tricking reflection into
    // letting us modify the static final field
    Field modifiersField = Field.class.getDeclaredField("modifiers");
    modifiersField.setAccessible(true);
    int modifiers = modifiersField.getInt(field);

    // blank out the final bit in the modifiers int
    modifiers &= ~Modifier.FINAL;
    modifiersField.setInt(field, modifiers);

    FieldAccessor fa = ReflectionFactory.getReflectionFactory().newFieldAccessor(field, false);
    fa.set(target, value);
}
 
開發者ID:boy0001,項目名稱:FastAsyncWorldedit,代碼行數:21,代碼來源:ReflectionUtils.java

示例3: createPristineURL

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
private static URL createPristineURL() {
    // Creates a pristine, incomplete URL object, that gets created when we
    // step into new URL(), for instance.
    ReflectionFactory rf = ReflectionFactory.getReflectionFactory();
    try {
        Constructor constructor = rf.newConstructorForSerialization(URL.class, Object.class.getDeclaredConstructor());
        Object newInstance = constructor.newInstance();
        return (URL) newInstance;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:MirrorValuesApp.java

示例4: createWithConstructor

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
@SuppressWarnings ( {"unchecked"} )
public static <T> T createWithConstructor ( Class<T> classToInstantiate, Class<? super T> constructorClass, Class<?>[] consArgTypes, Object[] consArgs )
        throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
    Constructor<? super T> objCons = constructorClass.getDeclaredConstructor(consArgTypes);
    objCons.setAccessible(true);
    Constructor<?> sc = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(classToInstantiate, objCons);
    sc.setAccessible(true);
    return (T)sc.newInstance(consArgs);
}
 
開發者ID:hucheat,項目名稱:APacheSynapseSimplePOC,代碼行數:10,代碼來源:Reflections.java

示例5: run

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
@Override
public Constructor<ServletPrintWriterDelegate> run() {
    try {
        return (Constructor)ReflectionFactory.getReflectionFactory().newConstructorForSerialization(ServletPrintWriterDelegate.class, Object.class.getDeclaredConstructor());
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:ServletPrintWriterDelegate.java

示例6: Bridge

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
private Bridge()
{
    latestUserDefinedLoaderMethod = getLatestUserDefinedLoaderMethod();
    unsafe = getUnsafe() ;
    reflectionFactory = (ReflectionFactory)AccessController.doPrivileged(
        new ReflectionFactory.GetReflectionFactoryAction());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:8,代碼來源:Bridge.java

示例7: copyFields

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
private static Field[] copyFields(Field[] arg) {
    Field[] out = new Field[arg.length];
    ReflectionFactory fact = getReflectionFactory();
    for (int i = 0; i < arg.length; i++) {
        out[i] = fact.copyField(arg[i]);
    }
    return out;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:Class.java

示例8: copyMethods

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
private static Method[] copyMethods(Method[] arg) {
    Method[] out = new Method[arg.length];
    ReflectionFactory fact = getReflectionFactory();
    for (int i = 0; i < arg.length; i++) {
        out[i] = fact.copyMethod(arg[i]);
    }
    return out;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:Class.java

示例9: copyConstructors

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
private static <U> Constructor<U>[] copyConstructors(Constructor<U>[] arg) {
    Constructor<U>[] out = arg.clone();
    ReflectionFactory fact = getReflectionFactory();
    for (int i = 0; i < out.length; i++) {
        out[i] = fact.copyConstructor(out[i]);
    }
    return out;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:Class.java

示例10: getReflectionFactory

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
private static ReflectionFactory getReflectionFactory() {
    if (reflectionFactory == null) {
        reflectionFactory =
            java.security.AccessController.doPrivileged
                (new sun.reflect.ReflectionFactory.GetReflectionFactoryAction());
    }
    return reflectionFactory;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:Class.java

示例11: createEmptyObject

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
public static <T> Optional<T> createEmptyObject(Class<T> clazz) {
    ReflectionFactory factory = ReflectionFactory.getReflectionFactory();
    Optional<T> optional;
    try {
        Constructor objDef = Object.class.getDeclaredConstructor();
        Constructor constr = factory.newConstructorForSerialization(clazz, objDef);
        optional = Optional.ofNullable(clazz.cast(constr.newInstance()));
    } catch(NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
        e.printStackTrace();
        optional = Optional.empty();
    }
    return optional;
}
 
開發者ID:OrigamiDream,項目名稱:Leveled-Storage,代碼行數:14,代碼來源:Storages.java

示例12: createWithConstructor

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
@SuppressWarnings ( {
    "unchecked"
} )
public static <T> T createWithConstructor ( Class<T> classToInstantiate, Class<? super T> constructorClass, Class<?>[] consArgTypes,
        Object[] consArgs ) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
    Constructor<? super T> objCons = constructorClass.getDeclaredConstructor(consArgTypes);
    objCons.setAccessible(true);
    Constructor<?> sc = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(classToInstantiate, objCons);
    sc.setAccessible(true);
    return (T) sc.newInstance(consArgs);
}
 
開發者ID:mbechler,項目名稱:marshalsec,代碼行數:12,代碼來源:Reflections.java

示例13: getConstructor

import sun.reflect.ReflectionFactory; //導入依賴的package包/類
private static Constructor<?> getConstructor(Class<?> type)
    throws NoSuchMethodException
{
    ReflectionFactory factory = ReflectionFactory.getReflectionFactory();
    Constructor<?> objectConstructor = type.getConstructor((Class[]) null);

    @SuppressWarnings("unchecked")
    Constructor<?> c = (Constructor<?>) factory
            .newConstructorForSerialization(type, objectConstructor);
    return c;
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:12,代碼來源:NewConstructorForSerialization.java


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