简体   繁体   中英

from "array version" of a class to the class with reflection in java

ie i have "[B" but I want "B" as a Class type I tried this:

String tmp = clazz.getName();
tmp=tmp.substring(1);
clazz=Class.forName(tmp);

but it doesn't work because I use B while it want byte I suppose

I want this code to work with every class not just byte.

Sorry for the bad explanations, I'm new to this. thanks in advance.

For an array of primitives, Class.getName() will return only a single letter; that's described in the documentation .

Have a look to Class.getComponentType() , it should solve your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM