How to create a parameter constructor for class.forName in j2me
Sample Code:
Class A
{
A()
{
}
A(int a)
{
}
}
//Here is code to call a constructor
Object o = Class.fo开发者_如何转开发rName("org.java.DataMembers.A").newInstance();
How to call a parameter constructor in j2me..plz help
Pretty sure the answer is that you can't. If it's a class you are in charge of, you'll need to create a parameterless constructor... if not, you'll need to find another way to do what you want.
You could use this:
Class myClass = Class.forName("org.java.DataMembers.A");
Constructor intConstructor= myClass.getConstructor( Integer.TYPE)
Object o = intConstructor.newInstance( 4);
精彩评论