本文整理了Java中java.lang.reflect.Constructor.toString()
方法的一些代码示例,展示了Constructor.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Constructor.toString()
方法的具体详情如下:
包路径:java.lang.reflect.Constructor
类名称:Constructor
方法名:toString
[英]Returns a string containing a concise, human-readable description of this constructor. The format of the string is:
代码示例来源:origin: spring-projects/spring-loaded
public static String callToString(Constructor thiz) {
return thiz.toString();
}
代码示例来源:origin: jdbi/jdbi
@Override
public String toString() {
return constructor.toString();
}
}
代码示例来源:origin: org.testng/testng
@Override
public String toString() {
if (m_method != null) return m_method.toString();
else return m_constructor.toString();
}
}
代码示例来源:origin: cbeust/testng
@Override
public String toString() {
if (m_method != null) return m_method.toString();
else return m_constructor.toString();
}
代码示例来源:origin: bootique/bootique
private static Type propertyTypeFromConstructor(Constructor maybeConstructor) {
Type[] paramTypes = maybeConstructor.getGenericParameterTypes();
if (paramTypes.length != 1) {
throw new IllegalStateException("Constructor '" + maybeConstructor.toString()
+ "' is annotated with @BQConfigProperty, but does not match expected signature."
+ " It must take exactly one parameter");
}
return paramTypes[0];
}
代码示例来源:origin: Bukkit/Bukkit
protected ConfigurationSerializable deserializeViaCtor(Constructor<? extends ConfigurationSerializable> ctor, Map<String, ?> args) {
try {
return ctor.newInstance(args);
} catch (Throwable ex) {
Logger.getLogger(ConfigurationSerialization.class.getName()).log(
Level.SEVERE,
"Could not call constructor '" + ctor.toString() + "' of " + clazz + " for deserialization",
ex instanceof InvocationTargetException ? ex.getCause() : ex);
}
return null;
}
代码示例来源:origin: thinkaurelius/titan
@SuppressWarnings("unchecked")
private static <V> V instantiate(String policyClassName, Integer[] args, String raw) throws Exception {
for (Constructor<?> con : Class.forName(policyClassName).getConstructors()) {
Class<?>[] parameterTypes = con.getParameterTypes();
// match constructor by number of arguments first
if (args.length != parameterTypes.length)
continue;
// check if the constructor parameter types are compatible with argument types (which are integer)
// note that we allow long.class arguments too because integer is cast to long by runtime.
boolean intsOrLongs = true;
for (Class<?> pc : parameterTypes) {
if (!pc.equals(int.class) && !pc.equals(long.class)) {
intsOrLongs = false;
break;
}
}
// we found a constructor with required number of parameters but times didn't match, let's carry on
if (!intsOrLongs)
continue;
if (log.isDebugEnabled())
log.debug("About to instantiate class {} with {} arguments", con.toString(), args.length);
return (V) con.newInstance(args);
}
throw new Exception("Failed to identify a class matching the Astyanax Retry Policy config string \"" + raw + "\"");
}
代码示例来源:origin: AdoptOpenJDK/jitwatch
public MetaConstructor(Constructor<?> constructor, MetaClass methodClass)
{
super(StringUtil.getUnqualifiedMemberName(constructor.getName()));
this.constructorToString = constructor.toString();
this.metaClass = methodClass;
returnType = Void.TYPE;
paramTypes = Arrays.asList(constructor.getParameterTypes());
modifier = constructor.getModifiers();
isVarArgs = constructor.isVarArgs();
if (DEBUG_MEMBER_CREATION)
{
logger.debug("Created MetaConstructor: {}", toString());
}
}
代码示例来源:origin: AdoptOpenJDK/jitwatch
public MetaConstructor(Constructor<?> constructor, MetaClass methodClass)
{
super(StringUtil.getUnqualifiedMemberName(constructor.getName()));
this.constructorToString = constructor.toString();
this.metaClass = methodClass;
returnType = Void.TYPE;
paramTypes = Arrays.asList(constructor.getParameterTypes());
modifier = constructor.getModifiers();
isVarArgs = constructor.isVarArgs();
if (DEBUG_MEMBER_CREATION)
{
logger.debug("Created MetaConstructor: {}", toString());
}
}
代码示例来源:origin: robovm/robovm
result.append(declaringClass.getName());
result.append("(");
result.append(toString(parameterTypes));
result.append(")");
if (exceptionTypes != null && exceptionTypes.length != 0) {
result.append(" throws ");
result.append(toString(exceptionTypes));
代码示例来源:origin: robovm/robovm
if (!checkAccessible(caller, this)) {
throw new IllegalAccessException(String.format("Attempt to access constructor %s(%s) from class %s",
clazz.getName(), toString(parameterTypes), caller.getName()));
代码示例来源:origin: jenkinsci/configuration-as-code-plugin
".\n Constructor: " + constructor.toString() +
".\n Arguments: " + argumentTypes, ex);
代码示例来源:origin: org.elasticsearch/elasticsearch
@Override
public String toString() {
return constructor.toString();
}
}
代码示例来源:origin: stackoverflow.com
Class obj2Class = object2.getClass();
try
{
Constructor[] ctors = obj2Class.getDeclaredConstructors();
for (Constructor cc : ctors)
{
System.out.println("my ctor is " + cc.toString());
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
代码示例来源:origin: spring-projects/spring-loaded
Assert.assertEquals("public reflection.constructors.ClassForNewInstance(char,char)", c.toString());
代码示例来源:origin: stackoverflow.com
public static Object createObject(Constructor constructor,
Object[] arguments) {
System.out.println("Constructor: " + constructor.toString());
Object object = null;
try {
object = constructor.newInstance(arguments);
System.out.println("Object: " + object.toString());
return object;
} catch (InstantiationException e) {
//handle it
} catch (IllegalAccessException e) {
//handle it
} catch (IllegalArgumentException e) {
//handle it
} catch (InvocationTargetException e) {
//handle it
}
return object;
}
}
代码示例来源:origin: syncany/syncany
@Test
public void testMatchingConstructor() throws Exception {
final Constructor<?> reference = X.class.getConstructor(A.class, A.class);
assertNotNull(reference);
for (Constructor<?> c : X.class.getConstructors()) {
System.out.println(c.toString());
}
assertNotNull(ReflectionUtil.getMatchingConstructorForClass(X.class, A.class, A.class));
assertEquals(reference, ReflectionUtil.getMatchingConstructorForClass(X.class, A.class, A.class));
assertNotNull(ReflectionUtil.getMatchingConstructorForClass(X.class, A.class, C.class));
assertNotNull(ReflectionUtil.getMatchingConstructorForClass(X.class, A.class));
assertNotNull(ReflectionUtil.getMatchingConstructorForClass(X.class, B.class));
assertNull(ReflectionUtil.getMatchingConstructorForClass(X.class, A.class, B.class)); // type erasure :(
assertNull(ReflectionUtil.getMatchingConstructorForClass(X.class, B.class, B.class));
assertNull(ReflectionUtil.getMatchingConstructorForClass(X.class, B.class, A.class));
assertNull(ReflectionUtil.getMatchingConstructorForClass(X.class, A.class, B.class, B.class));
assertNull(ReflectionUtil.getMatchingConstructorForClass(X.class));
}
代码示例来源:origin: resteasy/Resteasy
throw new RuntimeException(Messages.MESSAGES.failedToConstruct(constructor.toString()), e);
throw new RuntimeException(Messages.MESSAGES.failedToConstruct(constructor.toString()), e);
throw new RuntimeException(Messages.MESSAGES.failedToConstruct(constructor.toString()), e.getCause());
String msg = Messages.MESSAGES.badArguments(constructor.toString() + " (");
boolean first = false;
for (Object arg : args)
代码示例来源:origin: resteasy/Resteasy
throw new InternalServerErrorException(Messages.MESSAGES.failedProcessingArguments(constructor.toString()), e);
}).thenApply(args -> {
try
throw new InternalServerErrorException(Messages.MESSAGES.failedToConstruct(constructor.toString()), e);
throw new InternalServerErrorException(Messages.MESSAGES.failedToConstruct(constructor.toString()), e);
throw new ApplicationException(Messages.MESSAGES.failedToConstruct(constructor.toString()), e.getCause());
String msg = Messages.MESSAGES.badArguments(constructor.toString() + " (");
boolean first = false;
for (Object arg : args)
代码示例来源:origin: org.drools/drools-core
fail( "Unexpected constructor: " + c.toString() );
内容来源于网络,如有侵权,请联系作者删除!