Generic Methods
package com.gs.corejava.collections;
public class Generic3 {
static <T> void genericDisplay(T arg) {
System.out.println(arg);
}
public static void main(String[] args) {
genericDisplay(12);
genericDisplay(13.4);
genericDisplay("mohit");
}
}12
13.4
mohitGENERIC METHODS DEFINED IN A NONGENERIC CLASS OR INTERFACE:

For a generic method (defined in a nongeneric class or inter-face), its type parameter list is placed just after the access and nonaccess modifiers and before its return type.
GENERIC METHODS DEFINED IN A GENERIC CLASS OR INTERFACE:


Problem :
1)

2) What will be the output ?
3) What will be the output ?
Ans:
1)

Last updated
Was this helpful?