0

Can anyone explain this code?

What is static <T> void f(T x)? Is this a static block? static int =0; static <T> void f (T x) { System.out.println(++i); } public static void main (String [] args) { f(2); f(2.0); f(2); }

8th May 2017, 9:53 AM
Prathamesh Jadhav
Prathamesh Jadhav - avatar
2 odpowiedzi
+ 2
1. Your code contains error at "static int =0". 2. If we fix it then it will work such way: static <T> void f (T x) is a static function with a generic argument. Generic means it can be any object type (Integer, Double, String, Object, etc.). But function does nothing with this argument in its body and only increments static variable and then prints its value. So output of this code will be "1 2 3", each number in new line.
8th May 2017, 10:19 AM
Jeth
Jeth - avatar
0
Ok... Thanks a lot.
8th May 2017, 3:28 PM
Prathamesh Jadhav
Prathamesh Jadhav - avatar