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); }
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.
0
Ok... Thanks a lot.