I have seen a method like shown below:
protected T save( T Acd, boolean en) {
What does it do? What is these type of
It means that you must send an ABC object or a child of ABC, no other classes allowed. Also, your Acd variable could use the methods in ABC class that are visible to the class that contians the save method.
This is useful when your T class extends interfaces. For example, you're creating a class that handles object array sorting and this class must implement tne Comparable interface, otherwise the array won't be allowed:
class Class1 implements Comparable {
//attributes, getters and setters...
int x;
//implementing the interface...
public int compareTo(Class1 c1) {
//nice implementation of compareTo
return (this.x > c1.x)? 1 : (this.x < c1.x) ? 0 : -1;
}
}
class Class2 {
int x;
}
public class Sorter> {
public static void insertionSort(T[] array) {
//good implementation of insertion sort goes here...
//just to prove that you can use the methods of the Comparable interface...
array[0].compareTo(array[1]);
}
public static void main(String[] args) {
Class1[] arrC1 = new Class1[5];
Class2[] arrC2 = new Class2[5];
//fill the arrays...
insertionSort(arrC1); //good!
insertionSort(arrC2); //compiler error!
}
}