本文整理了Java中java.lang.reflect.Constructor.isAccessible()
方法的一些代码示例,展示了Constructor.isAccessible()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Constructor.isAccessible()
方法的具体详情如下:
包路径:java.lang.reflect.Constructor
类名称:Constructor
方法名:isAccessible
暂无
代码示例来源:origin: libgdx/libgdx
public boolean isAccessible () {
return constructor.isAccessible();
}
代码示例来源:origin: libgdx/libgdx
public boolean isAccessible () {
return constructor.isAccessible();
}
代码示例来源:origin: oldmanpushcart/greys-anatomy
@Override
public boolean isAccessible() {
return target.isAccessible();
}
代码示例来源:origin: alibaba/jvm-sandbox
@Override
public boolean isAccessible() {
return target.isAccessible();
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Make the given constructor accessible, explicitly setting it accessible
* if necessary. The {@code setAccessible(true)} method is only called
* when actually necessary, to avoid unnecessary conflicts with a JVM
* SecurityManager (if active).
* @param ctor the constructor to make accessible
* @see java.lang.reflect.Constructor#setAccessible
*/
@SuppressWarnings("deprecation") // on JDK 9
public static void makeAccessible(Constructor<?> ctor) {
if ((!Modifier.isPublic(ctor.getModifiers()) ||
!Modifier.isPublic(ctor.getDeclaringClass().getModifiers())) && !ctor.isAccessible()) {
ctor.setAccessible(true);
}
}
代码示例来源:origin: nutzam/nutz
public FallbackFastMethod(Constructor<?> constructor) {
this.constructor = constructor;
if (!this.constructor.isAccessible())
this.constructor.setAccessible(true);
}
代码示例来源:origin: nutzam/nutz
public AbstractConstructorBorning(Constructor<?> c) {
super();
if (!c.isAccessible())
c.setAccessible(true);
this.c = c;
}
代码示例来源:origin: ltsopensource/light-task-scheduler
public static <T> T newInstance(Class<T> clazz, ClassLoader classLoader, String className) throws Exception {
final Constructor<T> constructor = clazz.getDeclaredConstructor();
if (!constructor.isAccessible()) {
constructor.setAccessible(true);
}
CONSTRUCTOR_CACHE.put(classLoader, className, constructor);
return constructor.newInstance();
}
代码示例来源:origin: ltsopensource/light-task-scheduler
public static <T> T newInstance(Class<T> clazz, ClassLoader classLoader, String className) throws Exception {
final Constructor<T> constructor = clazz.getDeclaredConstructor();
if (!constructor.isAccessible()) {
constructor.setAccessible(true);
}
CONSTRUCTOR_CACHE.put(classLoader, className, constructor);
return constructor.newInstance();
}
代码示例来源:origin: jdbi/jdbi
private static MethodHandles.Lookup getConstructorLookup(Class<?> type) throws ReflectiveOperationException {
Constructor<MethodHandles.Lookup> constructor = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class);
if (!constructor.isAccessible()) {
constructor.setAccessible(true);
}
return constructor.newInstance(type, ANY_ACCESS);
}
}
代码示例来源:origin: org.springframework/spring-core
/**
* Make the given constructor accessible, explicitly setting it accessible
* if necessary. The {@code setAccessible(true)} method is only called
* when actually necessary, to avoid unnecessary conflicts with a JVM
* SecurityManager (if active).
* @param ctor the constructor to make accessible
* @see java.lang.reflect.Constructor#setAccessible
*/
@SuppressWarnings("deprecation") // on JDK 9
public static void makeAccessible(Constructor<?> ctor) {
if ((!Modifier.isPublic(ctor.getModifiers()) ||
!Modifier.isPublic(ctor.getDeclaringClass().getModifiers())) && !ctor.isAccessible()) {
ctor.setAccessible(true);
}
}
代码示例来源:origin: deeplearning4j/nd4j
public static void makeAccessible(Constructor<?> ctor) {
if ((!Modifier.isPublic(ctor.getModifiers()) || !Modifier.isPublic(ctor.getDeclaringClass().getModifiers()))
&& !ctor.isAccessible()) {
ctor.setAccessible(true);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
/**
* Checks whether the given class can be used by the {@link ConstructorBasedConverter} (i.e. has a constructor
* taking a single String as argument). If so, creates a new instance of converter for this type.
*
* @param clazz the class
* @return a {@link ConstructorBasedConverter} if the given class is eligible,
* {@literal null} otherwise.
*/
public static <T> ConstructorBasedConverter<T> getIfEligible(Class<T> clazz) {
try {
final Constructor<T> constructor = clazz.getConstructor(String.class);
if (!constructor.isAccessible()) {
constructor.setAccessible(true);
}
return new ConstructorBasedConverter<>(constructor);
} catch (NoSuchMethodException e) {
// The class does not have the right constructor, return null.
return null;
}
}
代码示例来源:origin: prestodb/presto
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Constructor<?> ctor = clazz.getDeclaredConstructor(_serialization.args);
// 06-Oct-2012, tatu: Has "lost" its security override, must force back
if (!ctor.isAccessible()) {
ClassUtil.checkAndFixAccess(ctor, false);
}
return new AnnotatedConstructor(null, ctor, null, null);
} catch (Exception e) {
throw new IllegalArgumentException("Could not find constructor with "
+_serialization.args.length+" args from Class '"+clazz.getName());
}
}
代码示例来源:origin: redisson/redisson
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Constructor<?> ctor = clazz.getDeclaredConstructor(_serialization.args);
// 06-Oct-2012, tatu: Has "lost" its security override, must force back
if (!ctor.isAccessible()) {
ClassUtil.checkAndFixAccess(ctor, false);
}
return new AnnotatedConstructor(null, ctor, null, null);
} catch (Exception e) {
throw new IllegalArgumentException("Could not find constructor with "
+_serialization.args.length+" args from Class '"+clazz.getName());
}
}
代码示例来源:origin: spring-projects/spring-framework
@SuppressWarnings("deprecation") // on JDK 9
public static Object newInstance(final Constructor cstruct, final Object[] args) {
boolean flag = cstruct.isAccessible();
try {
if (!flag) {
cstruct.setAccessible(true);
}
Object result = cstruct.newInstance(args);
return result;
}
catch (InstantiationException e) {
throw new CodeGenerationException(e);
}
catch (IllegalAccessException e) {
throw new CodeGenerationException(e);
}
catch (InvocationTargetException e) {
throw new CodeGenerationException(e.getTargetException());
}
finally {
if (!flag) {
cstruct.setAccessible(flag);
}
}
}
代码示例来源:origin: google/j2objc
public static Object newInstance(final Constructor cstruct, final Object[] args) {
boolean flag = cstruct.isAccessible();
try {
cstruct.setAccessible(true);
Object result = cstruct.newInstance(args);
return result;
} catch (InstantiationException e) {
throw new CodeGenerationException(e);
} catch (IllegalAccessException e) {
throw new CodeGenerationException(e);
} catch (InvocationTargetException e) {
throw new CodeGenerationException(e.getTargetException());
} finally {
cstruct.setAccessible(flag);
}
}
代码示例来源:origin: baomidou/mybatis-plus
private Object invokeDefaultMethod(Object proxy, Method method, Object[] args)
throws Throwable {
final Constructor<MethodHandles.Lookup> constructor = MethodHandles.Lookup.class
.getDeclaredConstructor(Class.class, int.class);
if (!constructor.isAccessible()) {
constructor.setAccessible(true);
}
final Class<?> declaringClass = method.getDeclaringClass();
return constructor
.newInstance(declaringClass,
MethodHandles.Lookup.PRIVATE | MethodHandles.Lookup.PROTECTED
| MethodHandles.Lookup.PACKAGE | MethodHandles.Lookup.PUBLIC)
.unreflectSpecial(method, declaringClass).bindTo(proxy).invokeWithArguments(args);
}
代码示例来源:origin: wildfly/wildfly
static Constructor<?> newConstructorForSerialization(Class<?> classToInstantiate, Constructor<?> constructorToCall) {
final Constructor<?> serCtor = reflectionFactory.newConstructorForSerialization(classToInstantiate, constructorToCall);
if (! serCtor.isAccessible()) {
// older JDK 8...
AccessController.doPrivileged(new SetAccessibleAction(serCtor));
}
return serCtor;
}
代码示例来源:origin: firebase/firebase-jobdispatcher-android
public static void assertHasSinglePrivateConstructor(Class<?> cls) throws Exception {
Constructor<?>[] constructors = cls.getDeclaredConstructors();
assertEquals("expected number of constructors to be == 1", 1, constructors.length);
Constructor<?> constructor = constructors[0];
assertFalse("expected constructor to be inaccessible", constructor.isAccessible());
constructor.setAccessible(true);
constructor.newInstance();
}
内容来源于网络,如有侵权,请联系作者删除!