Generic Methods
A generic method defines its own formal type parameters. You can define a generic method in a generic or a nongeneric class.
GENERIC METHODS DEFINED IN A NONGENERIC CLASS OR INTERFACE:
A nongeneric class doesn’t define type parameters. To define a generic method in a nongeneric class or interface, you must define the type parameters with the method, in its type parameter section. A method’s type parameter list is placed just after its access and nonaccess modifiers and before its return type. Because a type parameter could be used to define the return type, it should be known before the return type is used. An example
GENERIC METHODS DEFINED IN A GENERIC CLASS OR INTERFACE:
The following example defines a generic interface, and a generic method that defines its own type parameter.
Problem :
1)
2) What will be the output ?
3) What will be the output ?
Ans:
1)
Last updated