How do I use getConstructor(params).newInstance(args)?

后端 未结 3 1698
谎友^
谎友^ 2021-02-02 09:10

This could well be a stupid question, but I\'m new to Java, so...

I\'ve currently got some code where currently this is being used clazz.asSubclass(asSubclassOfCla

3条回答
  •  醉酒成梦
    2021-02-02 09:35

    clazz.asSubclass(asSubclassOfClass)
         .getConstructor(String.class, XYZ.class)
         .newInstance("howdy", XyzObj)
    

    Which assumes that the constructor args are in the specified order

提交回复
热议问题