This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Deepika Joshi wrote:static <T> void myMethod (T  a Collection <T> c)
I am learning generics and I am not sure role of <T> next to 'static'...
Can you please write how to read it (static <T>), and what is use of <T>
Oh that is what i just studied [still i'm not perfect, but can give you a clue]
T stands for "type" & E stands for "element"
Now if you make a generic class than you will declare the type in the class itself as
but sometimes you don't need to make a generic class and you only need to make generic method, that is when you have to declare your method in such a way so that you can place the type element of class in your method:
It is also worth knowing that Type parameters cannot be used in a static context, and thus cannot be used with static methods or variables, or enums. Also Exceptions and anonymous inner classes cannot be generic classes.
Generics have an optional syntax for specifying the type for a generic method call. You can place the data type of the generic in angle brackets, < > , after the dot operator and before the method name ie obj.<String>method("String");