CJCoding With Joseph
15per day
← Back to Question List
Java Code Walkthrough #38

Generic Identity Method

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