I need to get a list of field names and their types within a class and do formatted output.
Often the type is a generic such as the following:
In this case, I would want to print a line that looks like:
Questions:
1) How do I determine whether the type is a generic?
2) How do I determine and what the parameterized type is? By "parameterized type," I mean the "myType" in the example above.
3) Are the angle brackets available in any list of modifiers for the field?
I'm using the following loop to get my information:
Let me know if my post does not make sense -- when it came time to write this, I had a hard time finding the words!
Thanks,
Steve
Often the type is a generic such as the following:
Code:
java.util.List<myType>
In this case, I would want to print a line that looks like:
Code:
java.util.List<myType> myFieldName
Questions:
1) How do I determine whether the type is a generic?
2) How do I determine and what the parameterized type is? By "parameterized type," I mean the "myType" in the example above.
3) Are the angle brackets available in any list of modifiers for the field?
I'm using the following loop to get my information:
Code:
Field[] f = myClass.getDeclaredFields();
for ( Field aField : f)
{
String fldName = aField.getName();
Class fldTypeCls = aField.getType();
String fldType = fldTypeCls.getSimpleName();
}
Let me know if my post does not make sense -- when it came time to write this, I had a hard time finding the words!
Thanks,
Steve