private String getMainTitle(List<String> bs){
for(String b:bs){
if (b.equals("GOOD"){
return "string";
}
}
return null;
}
private String getMainTitle(String b){
if (b.equals("GOOD"){
return "string";
}
return null;
}
public String getTitleFromString(String b){
return getMainTitle(b);
}
public String getTitleFromList(List<String> bs){
return getMainTitle(bs);
}
請問怎样在JAVA寫一個含未知類的參數的方法?
希望寫一個方法能替代getTitleFromString和getTitleFromList , 比如:
public String getTitleFromList(T<?> t){
return getMainTitle(t);
}
但我的語法有誤, 請問該怎样改寫?
4 回答
大话西游666
TA贡献1817条经验 获得超14个赞
private String getMainTitle(List<String> bs){
for(String b:bs){
if (b.equals("GOOD")) {
return "string";
}
}
return null;
}
private String getMainTitle(String b){
if (b.equals("GOOD")) {
return "string";
}
return null;
}
public String getTitleFrom(String b){
return getMainTitle(b);
}
public String getTitleFrom(List<String> bs){
return getMainTitle(bs);
}
添加回答
举报
0/150
提交
取消