โ Back to Polymorphism
Question 595
Generic Method (Parametric Polymorphism)
Generic Method (Parametric Polymorphism)
Generics let one method work with ANY type. Write a generic methodIdentity<T>in theUtilclass that takes a value of typeTand returns it unchanged. The same method then works forint,string, or anything else. Do NOT write aMainmethod. The tester calls it with anintand astring, so the program prints: 42 hi
Expected Output:
42 hi
Topics:
Polymorphism
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.