CCB Premier Import
This commit is contained in:
36
11-SOURCES/generique/CoupleDiff.java
Normal file
36
11-SOURCES/generique/CoupleDiff.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package generique;
|
||||
|
||||
class CoupleDiff<T, U> {
|
||||
private T x; // le premier element du couple
|
||||
private U y; // le second element du couple
|
||||
|
||||
public CoupleDiff(T premier, U second) {
|
||||
x = premier;
|
||||
y = second;
|
||||
}
|
||||
|
||||
public T getPremier() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void affiche() {
|
||||
System.out.println ("Couple diff 1ere val : " + x + " - 2e val : " + y ) ;
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
Integer oi1 = 3;
|
||||
Double od1 = 2.5;
|
||||
CoupleDiff<Integer, Double> ch1 = new CoupleDiff<Integer, Double>(oi1,
|
||||
od1);
|
||||
ch1.affiche();
|
||||
|
||||
Integer oi2 = 4;
|
||||
CoupleDiff<Integer, Integer> ch2 = new CoupleDiff<Integer, Integer>(oi1, oi2);
|
||||
ch2.affiche();
|
||||
|
||||
Integer n = ch1.getPremier();
|
||||
System.out.println("premier element du couple ch1 = " + n);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user