开发者

parameter constructor for class.forName in j2me

开发者 https://www.devze.com 2023-02-13 11:35 出处:网络
How tocreate a parameter constructor for class.forName in j2me Sample Code: Class A { A() { } A(int a) { } } //Here is code to call a constructor

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号