CJCoding With Joseph
15free / daySign inCreate account
Back to Code Walkthrough

Generic Identity Method

Java code walkthrough · Question 38
easyGenerics, Methods

Code

Read carefully. What does this print?
1public class Main {
2 public static <T> T identity(T value) {
3 return value;
4 }
5 
6 public static void main(String[] args) {
7 String s = identity("world");
8 int n = identity(7);
9 System.out.println(s);
10 System.out.println(n);
11 }
12}

Your answer