Java Generics : Syntax Explanation

前端 未结 3 1513
遇见更好的自我
遇见更好的自我 2021-01-14 20:54

I am new to java generics my question is :

public static < E > void printArray( E[] inputArray )

In the above statement when the retu

3条回答
  •  悲哀的现实
    2021-01-14 21:46

    By you define a generic variable type, if you will write

    public static void printArray( E[] inputArray )
    

    Java will try to find a class with name E, because you don't define E as a generic. The return value in both cases are null, this generic definition part in not a part of return value, it's a separate block of function signature.

提交回复
热议问题