Results 1 to 2 of 2
Thread: Type wildcards in Generic
- 10-22-2010, 03:50 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 1
- Rep Power
- 0
Type wildcards in Generic
Hi
I would appreciate if any one would please correct whats wrong in my code. at line // <<<<< ERROR
Java Code://////////////////////////////////////////// // Type wild cards class Base<T> { protected LinkedList<T> items = new LinkedList<T>(); public void enqueue(T item){ items.addLast(item); } public T dequeue(){ return items.removeFirst(); } public boolean isEmply(){ return (items.size() == 0); } public void addAll(Collection<? extends T> coll){ // add all items from coll to the end of the queue for(T item : coll) enqueue(item); } } // end of class Base class A<T> extends Base<T>{ public void enqueue(T item){ System.out.println("Class A"); items.addLast(item); } public T dequeue(){ System.out.println("Class A"); return items.removeFirst(); } public boolean isEmply(){ System.out.println("Class A"); return (items.size() == 0); } public void addAll(Collection<? extends T> coll){ System.out.println("Class A"); // add all items from coll to the end of the queue for(T item : coll) enqueue(item); } } //end of class A class B<T> extends Base<T>{ public void enqueue(T item){ System.out.println("Class B"); items.addLast(item); } public T dequeue(){ System.out.println("Class B"); return items.removeFirst(); } public boolean isEmpty(){ System.out.println("Class B"); return (items.size() == 0); } public void addAll(Collection<? extends T> coll){ System.out.println("Class B"); // add all items of coll to the endof the queue for(T item: coll) enqueue(item); } } // endof class B Base<Integer> intBase = new Base<Integer>(); A<Integer> intA = new A<Integer>(); B<Integer> intB = new B<Integer>(); intA.enqueue(10); //<<<<< ERROR
- 10-22-2010, 04:39 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Generic return type is not inferred in for-each loop
By ranma173 in forum Advanced JavaReplies: 5Last Post: 10-08-2010, 11:50 AM -
Generic collection type
By dreuzel in forum Advanced JavaReplies: 7Last Post: 12-23-2009, 06:05 PM -
Generics and Wildcards
By ajeeb in forum Advanced JavaReplies: 2Last Post: 01-30-2009, 11:00 PM -
[SOLVED] Cast string type to int type
By GilaMonster in forum New To JavaReplies: 9Last Post: 09-17-2008, 10:43 AM -
The type Class is not generic; it cannot be parameterized with arguments <T>
By new_2_java in forum Advanced JavaReplies: 1Last Post: 05-16-2008, 11:06 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks