正在学习反射,遇到了无法找到构造函数的问题。

public class TestClass
{
private string _value;
public TestClass()
{
}
public TestClass(string value)
{
_value = value;
}
public string GetValue(string prefix)
{
。。。。。。

}}

Type t = typeof(ClassLibrary1.TestSpace);
object[] obj = new object[] { "timmy" };
PropertyInfo[] p = t.GetProperties();
MethodInfo[] m = t.GetMethods();
object DOBJ = Activator.CreateInstance(t,obj);
最后一步出现无法找到构造函数的错。

直接这样写不更好?

Constructor<?>[] constructor = Class.forName(className).getDeclaredConstructors();
Object obj = constructor[0].newInstance(参数);