Im trying to iterate a List. Im working with ASM, and usually I use
for(MethodNode methodNode:(List<MethodNode>) classNode.methods){
//...
}
to iterate my Lists.
but when I try to iterate a List of String's
for(String interfaceName:(List<String>) classNode.interfaces){
//...
}
my IDE gives me "Can only iterate over an array or an instance of java.lang.Iterable" error.
@Params classNode.interfaces returns a List <String>(http://asm.ow2.org/asm50/javadoc/user/org/objectweb/asm/tree/ClassNode.html#interfaces)
Edit: I figured it out! For those who were wondering what I did I figured Id post it!
for(Object strName: classNode.interfaces){
//use String.valueOf(strName) to obtain type string
}
This happens because for whatever reasons, the asm binary distribution comes with a jar stripped of generic signatures metadata. For development purposes, you should add asm-debug-all-5.2.jar to your classpath, then your IDE won't complain at you and you won't have to make strings out of things which are already strings. Here's the difference queried from each archive with javap
➤ javap -cp asm-all-5.2.jar org.objectweb.asm.tree.ClassNode | grep interfaces
public java.util.List interfaces;
➤ javap -cp asm-debug-all-5.2.jar org.objectweb.asm.tree.ClassNode | grep interfaces
public java.util.List<java.lang.String> interfaces;