Generic method

 public class GenericExample {

 public static <T> void printArray(T[] array) {

 for (T element : array) {

 System.out.println(element);

 }

 }

 public static void main(String[] args) {

 Integer[] intArray = {1, 2, 3};

 String[] strArray = {"A", "B", "C"};

 printArray(intArray);

 printArray(strArray);

 }

}


Comments

Popular posts from this blog

10. Vehicle and Car

Interface with Rectangle

Multiple interface