albertlee Posted August 13, 2006 Posted August 13, 2006 public <T> void meth1(T extends Something a){..}; public <T extends Something> void meth2(T a){...}; public <T extends Something> void meth3(T extends Something a){...}; Can any one tell me the difference between these 3??? please help thx
albertlee Posted August 13, 2006 Author Posted August 13, 2006 btw... Can any explain, with examples, the real difference between wilcard type method and generic type method in practice? The only thing it seems to me is that generic type is more concrete, hence we can, for example, add elements to a collection while with wildcard type, we are like assuming to take any thing unknown.... please help
albertlee Posted August 14, 2006 Author Posted August 14, 2006 ok... I understand the 1st question...please ignore... for the second question, an example is: static <T extends Shape> void draw(List<T> l) {drawOnCanvas(l.get(0));} versus static void draw(List<? extends Shape> l) {drawOnCanvas(l.get(0));} The above code should elaborate what I mean! please help thx
albertlee Posted August 14, 2006 Author Posted August 14, 2006 3rd question... Simply put, why cant we declare an array of generic types??? please help, along with the 2nd question... thx
albertlee Posted August 14, 2006 Author Posted August 14, 2006 btw, why I cant compile this code? public class b{ static class a{} static class b1 extends a{} static class c extends b{} static <A extends b.a> void adds(LinkedList<A> l, A b1){l.[b]add(b1)[/b];} static public void main(String[] sfg){ LinkedList<c> l = new LinkedList<c>(); adds(l, new c()); } } and the problem originates from the bold part of the code above....during compile time. Please help thx
Aeternus Posted August 14, 2006 Posted August 14, 2006 btw' date=' why I cant compile this code? public class b{ static class a{} static class b1 extends a{} static class c extends b{} static <A extends b.a> void adds(LinkedList<A> l, A b1){l.[b]add(b1)[/b];} static public void main(String[] sfg){ LinkedList<c> l = new LinkedList<c>(); adds(l, new c()); } } and the problem originates from the bold part of the code above....during compile time. Please help thx[/quote'] static class c extends b{} to static class c extends b1{} A good example of why you should try naming classes better
albertlee Posted August 14, 2006 Author Posted August 14, 2006 thx Aeternus...but can you help me with other questions on this thread? Which refer to the 2nd, 3rd, and 4th posts here. thx
Pleiades Posted September 23, 2006 Posted September 23, 2006 Could you copy-paste the output form the compiler regarding the compile-time errors? Also, I've never seen angle brackets <> in java what’s going on here?
Aeternus Posted September 24, 2006 Posted September 24, 2006 Could you copy-paste the output form the compiler regarding the compile-time errors? Also, I've never seen angle brackets <> in java what’s going on here? The angled brackets are for passing type arguments to classes/methods etc when dealing with generics (feature new to java in 1.5).
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now