Salve, volevo capire perchè se creo un oggetto "TIPO" e istanzio una PriorityQueue<TIPO>
quando utilizzo "TIPO b = pq.peek();" perchè devo fare un casting?
pq.peek(): non dovrebbe restituire l'oggetto che ho inserito nella coda?
Esempio:
Grazie in anticipo.Codice PHP:public class Studente{...}
private Comparator<Studente> cmp = new Comparator<Studente>(){
public int compare(Studente a, Studente b){
if(a.getTipo()<b.getTipo() ){return -1;}
else if(a.getTipo()==b.getTipo()){ return 0; }
return 1;
}
};
PriorityQueue<Studente> pq = PriorityQueue<Studente>(20, cmp);
Studente a = new Studente(...);
pq.offer(a);
Studente b = pq.peek();// qui mi da errore, dice che devo fare CASTING...PERCHE'?

Rispondi quotando
