How to instantiate Class class for a primitive type?

前端 未结 4 2176
谎友^
谎友^ 2021-01-01 17:19

I\'m trying to do this, but doesn\'t work:

public static Class loadIt(String name) throws Throwable {
  return Class.forName(name);
}
assert foo.loadIt(\"int         


        
4条回答
  •  孤独总比滥情好
    2021-01-01 17:25

    In this case, the best you can hope for is to create a map of primitives to their Autoboxed equivalent and return a class of that type.

提交回复
热议问题