我有一个类,如下所示:
public class Test
{
private Long id;
private Long locationId;
private Long anotherId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getLocationId() {
return locationId;
}
public void setLocationId(Long locationId) {
this.locationId = locationId;
}
public Long getAnotherId() {
return anotherId;
}
public void setAnotherId(Long anotherId) {
this.anotherId = anotherId;
}
}
我在不同的地方使用以下方法通过id、locationId或anotherId查找匹配的对象:
public Test getMatchedObject(List<Test> list,Long id )
{
for(Test vo : list)
if(vo.getId() != null && vo.getId().longValue() == id.longValue())
return vo;
}
public Test getMatchedLocationVO(List<Test> list,Long locationId )
{
for(Test vo : list)
if(vo.getLocationId() != null && vo.getLocationId().longValue() == locationId.longValue())
return vo;
}
public Test getMatchedAnotherVO(List<Test> list,Long anotherId )
{
for(Test vo : list)
if(vo.getAnotherId() != null && vo.getAnotherId().longValue() == anotherId.longValue())
return vo;
}
我针对每个参数使用了不同的方法来查找对象。有没有一种方法可以动态地传递方法名?
提前感谢...