No Anil,
When you used T in the instance method, it's is type declared by the class, that is only applicable with instance methods.
And when you used T in the static, you must declare that before using; One should not confuse with the similar name;
You make the static method display() type as:
static <E> void display(E e1) {
...
}
Didn't you see the static method is able to take any type in its argument while instance method is not. To the instance method, you can only pass
String, what the reference variable of the class MyType is parameterized with.
Hi Chandra
-----------------------------------
void show(T t1) {
System.out.println(t1); }
----------------------------------
change this code to this
-----------------------------------
static void show(T t1) {
System.out.println(t1); }
----------------------------------
You will get compiler error in the second one. Because you can't use class's
declared type with the static method. You must declare the type before using , in case of static method.
And in fact your class need not to be of parameterized type, only methods can be of generic type. But remember the type must be declared before using, in this case for static or instance methods both.
[ April 30, 2007: Message edited by: Chandra Bhatt ]