Assignment isn't working using generics in a simple way
I would very apprciate if someone could explain to me why u = bar(u,r) in following code isn't working. I just can't find the right explanation.
class R {
}
class U {
}
public class Foo {
public static <T> T bar(T x, T y) {
return x;
}
public static void main(String[] args) {
R r = new R();
U u = new U();
u = bar(u,r); // why is this not working?
}
}
I would very apprciate if someone could explain to me why u = bar(u,r) in following code isn't working. I just can't find the right explanation.
class R {
}
class U {
}
public class Foo {
public static <T> T bar(T x, T y) {
return x;
}
public static void main(String[] args) {
R r = new R();
U u = new U();
u = bar(u,r); // why is this not working?
}
}
No comments:
Post a Comment