GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 488 of 502    Print  
What's the difference between Object and "E"?
I'm trying to write an Iterator class for a LinkedList class that I wrote.
One of the methods is "public E next()"
I try to return an "E" but eclipse says "cannot convert from Object to E".
How do I fix this?



  
Total Answers and Comments: 4 Last Update: February 06, 2009     Asked by: esekiel 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: ravikishore_gvr
 
Object is a class where as E is nothing but Generic Argument, While writing Generic Classes we will use type E.

Above answer was rated as good by the following members:
er.mukesh_208, abhijitp
July 15, 2008 01:08:34   #1  
srinivasa123 Member Since: July 2008   Contribution: 1    

RE: What's the difference between Object and "E"?
change the method name as next1() it wil work.
 
Is this answer useful? Yes | No
July 16, 2008 02:54:33   #2  
ravikishore_gvr Member Since: July 2008   Contribution: 1    

RE: What's the difference between Object and "E"?
Object is a class where as E is nothing but Generic Argument While writing Generic Classes we will use type E.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
August 05, 2008 06:05:11   #3  
shishir11485 Member Since: August 2008   Contribution: 1    

RE: What's the difference between Object and "E"?
Object having a reference of one variable store in stack whereas "E" is created in a heap don't have a reference variable
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 3Overall Rating: -3    
February 06, 2009 16:19:59   #4  
kabir soni Member Since: February 2009   Contribution: 3    

RE: What's the difference between Object and "E"?
Object is a class and E is a generic type parameter . And Iterator class alwayes return Object so to fix this problem you need to call it. For example

import java.util.ArrayList;
import java.util.Iterator;


class list {
ArrayList list new ArrayList();
public E next() {
Iterator i list.iterator();
return (E)i.next();
}
}
public class TestProgram {

public static void main(String[] args) {
list list new list();
list.list.add( A );
System.out.println(list.next());
}
}



 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape