Why is <T> required in method signature, when a method takes generic params
Hello Everyone,
I'm new to Generics and I'm trying to understand Generics with respect to declaring a method with generic parameters.
I know how to write the code for this, below is an example of what I've tried so far and it works.
However, I don't really understand why I'm supposed to have something like <T> just before the method signature , shown below.
If I remove the <T> I get , a compile time error as shown in the comment below.
publicclass GenericsTest{
publicstaticvoid main(String[] args){
myGenericsMethod("Print a string");
myGenericsMethod(8);
myGenericsMethod(45.3F);
myGenericsMethod(1244);
}
/*
This gives an error "cannot find symbol class T"
if the <T> is removed
*/
privatestatic <T>void myGenericsMethod(T someGenericParameter){
System.out.println("someGenericParameter : " + someGenericParameter);
}
}
I couldn't find any documents that explain why <T> is required in the above case.
Any thoughts, explanation is appreciated.

