TD6
Collections & Générique
![](https://media.giphy.com/media/hfpUX0aptVMVa/giphy.gif)
Générique
![](https://media.giphy.com/media/XeFPw8TqdGv28/giphy.gif)
public class Jedi<T> {
private T corps;
private SabreLaser sabreLaser;
public Jedi(T corps){
this.corps = corps;
}
public SabreLaser getSabreLaser(){
return sabreLaser;
}
}
Chat chat = new Chat();
Chien chien = new Chien();
Jedi<Chat> miaouWalker = new Jedi<>(chat);
Jedi<Chien> woufWalker = new Jedi<Chien>(chien);
Collection
![](https://media.giphy.com/media/hpw20Q2CQbnRC/giphy.gif)
public class PersonneDansLeBus {
private int numeroSiege;
}
public class Bus {
private Collection<PersonneDansLeBus> collection;
public Bus {
collection = new ArrayList<>();
}
public void monteDansLeBus(PersonneDansLeBus p){
collection.add(p);
}
}
Map
![](https://media.giphy.com/media/KEVODnr6kaJws/giphy.gif)
public class PersonneDansLeBus {
protected int numeroSiege;
}
public class Bus {
private Map<Integer, PersonneDansLeBus> map;
public Bus {
map = new HashMap<>();
}
public void monteDansLeBus(PersonneDansLeBus p){
map.put(p.numeroSiege, p);
}
public PersonneDansLeBus getPersonne(int numeroSiege){
return map.get(numeroSiege);
}
}
Comparator
![](https://media.giphy.com/media/zujkOi1kkLRzG/giphy.gif)
public class PersonneDansLeBus {
protected int numeroSiege;
}
public class PersonneDansLeBusComparator implements Comparator<PersonneDansLeBus> {
public int compare(PersonneDansLeBus p1, PersonneDansLeBus p2){
return p1 - p2;
}
}
Interface Homme Machine
![](https://media.giphy.com/media/10xYprgFoZBprG/giphy.gif)
INSA - 2ième année - TD06
By Mickael Lecoq
INSA - 2ième année - TD06
- 998