B
Benjamin Lerman
Hi all,
Let's assume I have something that looks like the following:
import java.io.Serializable;
class A {
public static <K extends Serializable> K getFoo(Class<K> c) {
return c.newInstance();
}
public static <K extends Serializable> K getBar(K d) {
return getFoo(d.getClass());
}
}
When I try to compile that, I found:
dara /tmp $ javac A.java
A.java:10: incompatible types
found : java.io.Serializable
required: K
return getFoo(c.getClass());
^
1 error
Is there a reason for the compiler to refuse such a method ?
Thanks.
Let's assume I have something that looks like the following:
import java.io.Serializable;
class A {
public static <K extends Serializable> K getFoo(Class<K> c) {
return c.newInstance();
}
public static <K extends Serializable> K getBar(K d) {
return getFoo(d.getClass());
}
}
When I try to compile that, I found:
dara /tmp $ javac A.java
A.java:10: incompatible types
found : java.io.Serializable
required: K
return getFoo(c.getClass());
^
1 error
Is there a reason for the compiler to refuse such a method ?
Thanks.