迭代器返回一个Object而不是所需的对象

use*_*558 0 java iterator object

public class Facture {
private Client client = new Client();;
private float Paiement;
private float soustotal;
private float tps;
private float tvq;
private float ttc;
private List<LigneFacture> lignesFac = new ArrayList<LigneFacture>();

public Facture(){
    this.Paiement=0;
    this.soustotal=0;
    this.tps=0;
    this.tvq=0;
    this.ttc=0;

}
public Client getClient() {
    return client;
}

public void setClient(Client client) {
    this.client = client;
}

public float getPaiement() {
    return Paiement;
}

public void setPaiement(float Paiement) {
    this.Paiement = Paiement;
}

public float getSoustotal() {
    return soustotal;
}

public void setSoustotal(float soustotal) {
    this.soustotal = soustotal;
}

public float getTps() {
    return tps;
}

public void setTps(float tps) {
    this.tps = tps;
}

public float getTvq() {
    return tvq;
}

public void setTvq(float tvq) {
    this.tvq = tvq;
}

public float getTtc() {
    return ttc;
}

public void setTtc(float ttc) {
    this.ttc = ttc;
}

public List<LigneFacture> getLignesFac() {
    return lignesFac;
}
public void addLignesFacture(LigneFacture ligneFac){
    this.lignesFac.add(ligneFac);
    Iterator iter_lignesFact = lignesFac.iterator();

    while(iter_lignesFact.hasNext()){
       LigneFacture lignefac_cur =  iter_lignesFact.next();
    }
}
Run Code Online (Sandbox Code Playgroud)

}

嗨我有这个类,问题出在最后一个方法中,Java告诉我iter_lignesFact返回一个Object值而不是LigneFacture值,因此他希望我把它转换为LigneFacture,为什么呢?我在LigneFacture列表中定义了我的迭代器.

Jon*_*eet 14

你在这里使用了原始类型:

Iterator iter_lignesFact = lignesFac.iterator();
Run Code Online (Sandbox Code Playgroud)

您想使用通用表单:

Iterator<LigneFacture> iter_lignesFact = lignesFac.iterator();
Run Code Online (Sandbox Code Playgroud)