本文整理匯總了Java中sun.reflect.ReflectionFactory.getReflectionFactory方法的典型用法代碼示例。如果您正苦於以下問題:Java ReflectionFactory.getReflectionFactory方法的具體用法?Java ReflectionFactory.getReflectionFactory怎麽用?Java ReflectionFactory.getReflectionFactory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sun.reflect.ReflectionFactory
的用法示例。
在下文中一共展示了ReflectionFactory.getReflectionFactory方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
}
示例2: 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;
}
示例3: 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;
}
示例4: testInternalClasses
import sun.reflect.ReflectionFactory; //導入方法依賴的package包/類
@Test
@SuppressWarnings("SpellCheckingInspection,unchecked")
public void testInternalClasses() throws Exception
{
Object object;
ReflectionFactory reflection = ReflectionFactory.getReflectionFactory();
Constructor<?> constructor;
for(Class clazz : UUIDConverter.class.getDeclaredClasses())
{
constructor = reflection.newConstructorForSerialization(clazz, Object.class.getDeclaredConstructor());
object = constructor.newInstance();
switch(clazz.getName())
{
case "at.pcgamingfreaks.UUIDConverter$NameChange":
assertNotNull("The change date should not be null", clazz.getDeclaredMethod("getChangeDate").invoke(object));
break;
case "at.pcgamingfreaks.UUIDConverter$Profile":
assertNotNull("The object should not be null", object);
break;
case "at.pcgamingfreaks.UUIDConverter$CacheData":
SimpleDateFormat mockedDateFormat = mock(SimpleDateFormat.class);
doThrow(new ParseException("", 0)).when(mockedDateFormat).parse(anyString());
whenNew(SimpleDateFormat.class).withAnyArguments().thenReturn(mockedDateFormat);
Field expiresOn = clazz.getDeclaredField("expiresOn");
expiresOn.set(object, "2016-10-20 16:23:12 Z");
assertNotNull("The change date should not be null", clazz.getDeclaredMethod("getExpiresDate").invoke(object));
break;
}
}
}
示例5: create
import sun.reflect.ReflectionFactory; //導入方法依賴的package包/類
public static <T> T create(Class<T> clazz, Class<? super T> parent, Class<?>[] paramTypes, Object[] paramValues) throws IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
if (paramTypes == null) {
paramTypes = new Class[0];
}
if (paramValues == null) {
paramValues = new Object[0];
}
ReflectionFactory rf = ReflectionFactory.getReflectionFactory();
Constructor objDef = parent.getDeclaredConstructor(paramTypes);
Constructor intConstr = rf.newConstructorForSerialization(clazz, objDef);
return clazz.cast(intConstr.newInstance(paramValues));
}
示例6: getConstructor
import sun.reflect.ReflectionFactory; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Constructor<Object> getConstructor() {
try {
ReflectionFactory factory = ReflectionFactory.getReflectionFactory();
Constructor<Object> objectConstructor =type.getConstructor((Class[]) null);
Constructor<Object> c = (Constructor<Object>) factory.newConstructorForSerialization(type, objectConstructor);
return c;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例7: init
import sun.reflect.ReflectionFactory; //導入方法依賴的package包/類
@BeforeClass
static void init() {
factory = ReflectionFactory.getReflectionFactory();
}
示例8: Bridge
import sun.reflect.ReflectionFactory; //導入方法依賴的package包/類
private Bridge() {
reflectionFactory = ReflectionFactory.getReflectionFactory();
stackWalker = StackWalker.getInstance(
StackWalker.Option.RETAIN_CLASS_REFERENCE);
}
示例9: ObjectFactoryBuilderReflection
import sun.reflect.ReflectionFactory; //導入方法依賴的package包/類
ObjectFactoryBuilderReflection() throws NoSuchMethodException
{
_reflectionFactory = ReflectionFactory.getReflectionFactory();
_baseConstructor = Object.class.getDeclaredConstructor();
}
示例10: Bridge
import sun.reflect.ReflectionFactory; //導入方法依賴的package包/類
private Bridge()
{
latestUserDefinedLoaderMethod = getLatestUserDefinedLoaderMethod();
unsafe = getUnsafe() ;
reflectionFactory = ReflectionFactory.getReflectionFactory();
}