Originally posted by anil kumar:
Hi
i could not under stand these statements
------------------------------------------------------------------------
Type parameters must not appear in any static context of a generic type, which means that type parameters cannot be used in the declaration of static fields or methods or in static nested
types or static initializers.
----------------------------------------------------------------------
if this is true ,then why this class is compiled sucessfully;
class Gen <T>
{
public static <T> display(T t)
{
System.out.println("The value is : "+t);
}
}
In the above class i am not doing any thing.
i have created on static method.
cmbhatt
Hi Chandra
-----------------------------------
void show(T t1) {
System.out.println(t1); }
----------------------------------
change this code to this
-----------------------------------
static void show(T t1) {
System.out.println(t1); }
----------------------------------
cmbhatt
Hi Chandra,
Can you explain me the below code?
public static <T> display(T t) {
}
Here the T is not the T the class declares. It is just matter of same type name T. For the static method you have declared the type well before using it in the method.
cmbhatt
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Originally posted by Anil,
Hey
Chandra
I am not speaking about static method.I am speaking about static context.
like
class A<T>
{
static int k;
public static void setK(T a)
{
--
}
}
cmbhatt
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |