Java Reflection calling constructor with primitive types

后端 未结 6 1169
日久生厌
日久生厌 2020-11-29 10:07

I have a method in my test framework that creates an instance of a class, depending on the parameters passed in:

public void test(Object... constructorArgs)          


        
6条回答
  •  盖世英雄少女心
    2020-11-29 10:26

    Use Integer.TYPE instead of Integer.class.

    As per the Javadocs, this is "The Class instance representing the primitive type int."

    You can also use int.class. It's a shortcut for Integer.TYPE. Not only classes, even for primitive types you can say type.class in Java.

提交回复
热议问题