a-
exemplo de polimorfismo parametrico:
_____________________________________________________________________________________
package parametrics;
public class Copier <T>{
public void copy(T a[], T b[], int n) {
for (int i=0; i<n; i++)
a[i]=b[i];
}
}
_____________________________________________________________________________________
package parametrics;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Double f1[] = new Double[10];
Double f2[] = new Double[10];
Copier<Double> cpDouble = new Copier<>();
cpDouble.copy(f1, f2, 10);
String s1[]= new String[20];
String s2[] = new String[20];
Copier<String> cpString = new Copier<>();
cpString.copy(s1, s2, 15);
}
}