While creating a class, when I clicked on "create main method", eclipse created the below for me:
I understand that generics is typically used to provide the type for a collection, while entering elements in it such that we dont face issues while retrieving from it and we dont require casting.
What I dont understand is that what exactly does generic syntax mean with the method definition (as above)? What difference is this making in above case for example?
When I create a class in Eclipse I right-click on a package and select New, then Class. I get a dialog box where I enter the class name and so on, and it has an area headed "Which method stubs would you like to create?" If I check the one labelled "public static void main(String args)" then it does what you would expect.
So I assume you followed some other process. Could you tell us about it?
posted 2 weeks ago
Oh I remember now that how it had come .I had copy pasted some code from somewhere.
The same it does in all other places. It declares variables that hold a type. You can call the method and pass type arguments, usually for the purpose of getting a result that uses the same types.
Seeing as the main method has no return value and no parameters that use the type parameters, the declaration of the type parameters is useless. The original author likely made a mistake, and it shows you you should be careful when copying code without reviewing and understanding it first.
posted 1 week ago
Thanks, I read on Generic methods and that we can pass 1 or more type parameters this way like <K> or <K, V>, or <K, V, M > etc.