java getClass show String但变量在长对象中受到影响

时间:2014-03-26 09:45:34

标签: java arrays string casting

这段简单的代码令我头疼:

Set<Long> statutList = rechercheSalarieForm.getIdStatutList();

getIdStatutList()正在返回一组Longs

但是当我这样做时:

statutList.toArray()[0].getClass() 

rechercheSalarieForm.getIdStatutList().toArray()[0].getClass()

结果是:

(java.lang.Class<T>) class java.lang.String

这个statutList直接发送到DAO层,它不喜欢hibernate请求中的字符串。

如何在长数组中使用字符串?

编辑:

短节目:

public List<EffectifRupHistoriqueExtractionVO>   
generateExtractionRupHistorique(RechercheSalariesRupFormVO rechercheSalarieForm) throws       FunctionalException {

    Collection<Long> statutList = rechercheSalarieForm.getIdStatutList();
    // Some business/Dao call with statutList in parameter
}

Object RechercheSalariesRupFormVO:

public class RechercheSalariesRupFormVO extends ValueObject{
// some declaration
    private Set<Long> idStatutList;
    public Set<Long> getIdStatutList() {
        return idStatutList;
    }
}

1 个答案:

答案 0 :(得分:0)

这是一个解决方法(它的丑陋):

int size = rechercheSalarieForm.getIdStatutList().size();
Collection<Long> statutList = new ArrayList<Long>();
int i=0;
for (i = 0; i < size ; i++) {               
    statutList.add(Long.valueOf(rechercheSalarieForm.getIdStatutList().toArray()[i].toString()));
}

感谢他:https://stackoverflow.com/a/12881094/2369897

如果有人知道为什么......