本文整理了Java中java.lang.reflect.Constructor.getParameterTypes()
方法的一些代码示例,展示了Constructor.getParameterTypes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Constructor.getParameterTypes()
方法的具体详情如下:
包路径:java.lang.reflect.Constructor
类名称:Constructor
方法名:getParameterTypes
[英]Returns an array of the Class objects associated with the parameter types of this constructor. If the constructor was declared with no parameters, an empty array will be returned.
[中]返回与此构造函数的参数类型关联的类对象数组。如果构造函数声明时没有参数,则将返回空数组。
代码示例来源:origin: libgdx/libgdx
/** Returns an array of Class objects that represent the formal parameter types, in declaration order, of the constructor. */
public Class[] getParameterTypes () {
return constructor.getParameterTypes();
}
代码示例来源:origin: libgdx/libgdx
/** Returns an array of Class objects that represent the formal parameter types, in declaration order, of the constructor. */
public Class[] getParameterTypes () {
return constructor.getParameterTypes();
}
代码示例来源:origin: google/guava
@Override
public Boolean apply(Constructor<?> input) {
return asList(input.getParameterTypes()).contains(String.class);
}
})
代码示例来源:origin: spring-projects/spring-framework
private static Constructor<?> getEndpointConstructor() {
for (Constructor<?> current : TyrusEndpointWrapper.class.getConstructors()) {
Class<?>[] types = current.getParameterTypes();
if (Endpoint.class == types[0] && EndpointConfig.class == types[1]) {
return current;
}
}
throw new IllegalStateException("No compatible Tyrus version found");
}
代码示例来源:origin: apache/incubator-dubbo
public MapDeserializer(Class type) {
if (type == null)
type = HashMap.class;
_type = type;
Constructor[] ctors = type.getConstructors();
for (int i = 0; i < ctors.length; i++) {
if (ctors[i].getParameterTypes().length == 0)
_ctor = ctors[i];
}
if (_ctor == null) {
try {
_ctor = HashMap.class.getConstructor(new Class[0]);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}
代码示例来源:origin: spring-projects/spring-framework
public ReflectiveConstructorExecutor(Constructor<?> ctor) {
this.ctor = ctor;
if (ctor.isVarArgs()) {
Class<?>[] paramTypes = ctor.getParameterTypes();
this.varargsPosition = paramTypes.length - 1;
}
else {
this.varargsPosition = null;
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create an array of descriptors representing the parameter types for the supplied
* constructor. Returns a zero sized array if there are no parameters.
* @param ctor a Constructor
* @return a String array of descriptors, one entry for each constructor parameter
*/
public static String[] toParamDescriptors(Constructor<?> ctor) {
return toDescriptors(ctor.getParameterTypes());
}
代码示例来源:origin: spring-projects/spring-framework
protected Constructor<?> getUserDeclaredConstructor(Constructor<?> constructor) {
Class<?> declaringClass = constructor.getDeclaringClass();
Class<?> userClass = ClassUtils.getUserClass(declaringClass);
if (userClass != declaringClass) {
try {
return userClass.getDeclaredConstructor(constructor.getParameterTypes());
}
catch (NoSuchMethodException ex) {
// No equivalent constructor on user class (superclass)...
// Let's proceed with the given constructor as we usually would.
}
}
return constructor;
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Returns the descriptor corresponding to the given constructor.
*
* @param constructor a {@link Constructor} object.
* @return the descriptor of the given constructor.
*/
public static String getConstructorDescriptor(final Constructor<?> constructor) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append('(');
Class<?>[] parameters = constructor.getParameterTypes();
for (Class<?> parameter : parameters) {
appendDescriptor(parameter, stringBuilder);
}
return stringBuilder.append(")V").toString();
}
代码示例来源:origin: google/guava
/**
* Verifies that {@code ctor} produces a {@link NullPointerException} or {@link
* UnsupportedOperationException} whenever <i>any</i> of its non-nullable parameters are null.
*/
public void testConstructor(Constructor<?> ctor) {
Class<?> declaringClass = ctor.getDeclaringClass();
checkArgument(
Modifier.isStatic(declaringClass.getModifiers())
|| declaringClass.getEnclosingClass() == null,
"Cannot test constructor of non-static inner class: %s",
declaringClass.getName());
Class<?>[] types = ctor.getParameterTypes();
for (int nullIndex = 0; nullIndex < types.length; nullIndex++) {
testConstructorParameter(ctor, nullIndex);
}
}
代码示例来源:origin: spring-projects/spring-framework
private static boolean isApplicable(Member member, Class<?> sourceClass) {
if (member instanceof Method) {
Method method = (Method) member;
return (!Modifier.isStatic(method.getModifiers()) ?
ClassUtils.isAssignable(method.getDeclaringClass(), sourceClass) :
method.getParameterTypes()[0] == sourceClass);
}
else if (member instanceof Constructor) {
Constructor<?> ctor = (Constructor<?>) member;
return (ctor.getParameterTypes()[0] == sourceClass);
}
else {
return false;
}
}
代码示例来源:origin: apache/incubator-dubbo
/**
* get constructor desc.
* "()V", "(Ljava/lang/String;I)V"
*
* @param c constructor.
* @return desc
*/
public static String getDesc(final Constructor<?> c) {
StringBuilder ret = new StringBuilder("(");
Class<?>[] parameterTypes = c.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
ret.append(getDesc(parameterTypes[i]));
}
ret.append(')').append('V');
return ret.toString();
}
代码示例来源:origin: apache/incubator-dubbo
/**
* get constructor desc.
* "()V", "(Ljava/lang/String;I)V"
*
* @param c constructor.
* @return desc
*/
public static String getDesc(final Constructor<?> c) {
StringBuilder ret = new StringBuilder("(");
Class<?>[] parameterTypes = c.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
ret.append(getDesc(parameterTypes[i]));
}
ret.append(')').append('V');
return ret.toString();
}
代码示例来源:origin: jenkinsci/jenkins
private String getMethodDescriptor(Constructor c) {
StringBuilder buf = new StringBuilder();
buf.append('(');
for (Class p : c.getParameterTypes())
buf.append(Type.getDescriptor(p));
buf.append(")V");
return buf.toString();
}
}
代码示例来源:origin: org.mockito/mockito-core
public int compare(Constructor<?> constructorA, Constructor<?> constructorB) {
int argLengths = constructorB.getParameterTypes().length - constructorA.getParameterTypes().length;
if (argLengths == 0) {
int constructorAMockableParamsSize = countMockableParams(constructorA);
int constructorBMockableParamsSize = countMockableParams(constructorB);
return constructorBMockableParamsSize - constructorAMockableParamsSize;
}
return argLengths;
}
代码示例来源:origin: org.mockito/mockito-core
private void checkParameterized(Constructor<?> constructor, Field field) {
if(constructor.getParameterTypes().length == 0) {
throw new MockitoException("the field " + field.getName() + " of type " + field.getType() + " has no parameterized constructor");
}
}
代码示例来源:origin: google/guava
@Override
Type[] getGenericParameterTypes() {
Type[] types = constructor.getGenericParameterTypes();
if (types.length > 0 && mayNeedHiddenThis()) {
Class<?>[] rawParamTypes = constructor.getParameterTypes();
if (types.length == rawParamTypes.length
&& rawParamTypes[0] == getDeclaringClass().getEnclosingClass()) {
// first parameter is the hidden 'this'
return Arrays.copyOfRange(types, 1, types.length);
}
}
return types;
}
代码示例来源:origin: org.mockito/mockito-core
private int countMockableParams(Constructor<?> constructor) {
int constructorMockableParamsSize = 0;
for (Class<?> aClass : constructor.getParameterTypes()) {
if(MockUtil.typeMockabilityOf(aClass).mockable()){
constructorMockableParamsSize++;
}
}
return constructorMockableParamsSize;
}
};
代码示例来源:origin: spring-projects/spring-framework
public static Signature getSignature(Member member) {
if (member instanceof Method) {
return new Signature(member.getName(), Type.getMethodDescriptor((Method) member));
}
else if (member instanceof Constructor) {
Type[] types = TypeUtils.getTypes(((Constructor) member).getParameterTypes());
return new Signature(Constants.CONSTRUCTOR_NAME,
Type.getMethodDescriptor(Type.VOID_TYPE, types));
}
else {
throw new IllegalArgumentException("Cannot get signature of a field");
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public TypedValue execute(EvaluationContext context, Object... arguments) throws AccessException {
try {
ReflectionHelper.convertArguments(
context.getTypeConverter(), arguments, this.ctor, this.varargsPosition);
if (this.ctor.isVarArgs()) {
arguments = ReflectionHelper.setupArgumentsForVarargsInvocation(
this.ctor.getParameterTypes(), arguments);
}
ReflectionUtils.makeAccessible(this.ctor);
return new TypedValue(this.ctor.newInstance(arguments));
}
catch (Exception ex) {
throw new AccessException("Problem invoking constructor: " + this.ctor, ex);
}
}
内容来源于网络,如有侵权,请联系作者删除!