我正在编写一个扩展com.sun.javadoc.Doclet的doclet.
当我想要将ArrayList记录为方法的字段时,我希望获得泛型的类型(例如,当记录ArrayList<String>我想要获取的信息时,这是包含字符串的列表).
我只能获取信息,这是一个ArrayList.即使打电话
ParameterizedType paramType = fieldType.asParameterizedType();
Run Code Online (Sandbox Code Playgroud)
我只获取java.util.ArrayList而不是泛型的类型.
有人知道如何获得列表的泛型类型吗?
这是示例代码:
FieldDoc[] fields = classDoc.fields();
for (int k = 0; k < fields.length; k++) {
Type fieldType = fields[k].type();
if (fieldType.asParameterizedType() != null) {
ParameterizedType paramType = fieldType.asParameterizedType();
String qualiName = paramType.qualifiedTypeName(); // this equals "java.util.ArrayList"
fieldType.asParameterizedType().toString(); // this equals "java.util.ArrayList"
fieldType.asParameterizedType().typeName(); // this equals "ArrayList"
}
}
Run Code Online (Sandbox Code Playgroud) 我不明白为什么HashSet上的contains()在以下示例中返回false:
import java.util.HashSet;
import java.util.Set;
public class MyMatching {
private Integer[] id;
public MyMatching(Integer id1, Integer id2) {
this.id = new Integer[2];
id[0] = id1;
id[1] = id2;
}
public String getId() {
return id[0] + ":" + id[1];
}
@Override
public boolean equals(Object other) {
if (this == other)
return true;
if (other == null || (this.getClass() != other.getClass())) {
return false;
}
MyMatching otherMatching = (MyMatching) other;
return (getId().equals(otherMatching.getId()));
}
@Override
public int hashCode() {
int result = …Run Code Online (Sandbox Code Playgroud)