Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Generic Inheritance

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Generic Inheritance

    Hi,

    I have the following structure:
    public interface RequestData
    public interface ResponseData
    public interface Service<RequestData, ResponseData>
     
    public class FirstRequestData implements RequestData
    public class FirstResponseData implements ResponseData
     
    public interface FirstService extends Service<FirstRequestData, FirstResponseData>
    public class FirstImplService implements FirstService
    And I'm trying to use the code:
    Service<RequestData, ResponseData> s = new FirstImplService();
    But get this compilation error:
    Type mismatch: cannot convert from FirstImplService to Service<RequestData,ResponseData>

    Can you explain why and help me?

    Thanks.
    Last edited by helloworld922; July 19th, 2011 at 07:55 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Generic Inheritance

    It's the same reason you can't do this:

    List<Number> list = new ArrayList<Integer>();

    Recommended reading: Subtyping (The Java™ Tutorials > Learning the Java Language > Generics)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Inheritance
    By lewzax in forum Object Oriented Programming
    Replies: 4
    Last Post: July 8th, 2011, 01:51 PM
  2. Java Inheritance Help
    By danielparry in forum Java Theory & Questions
    Replies: 3
    Last Post: March 17th, 2011, 03:20 PM
  3. inheritance help
    By justin3492 in forum Object Oriented Programming
    Replies: 3
    Last Post: September 30th, 2010, 07:45 PM
  4. inheritance
    By b109 in forum Java Theory & Questions
    Replies: 3
    Last Post: May 30th, 2010, 09:23 PM
  5. Generic programming example
    By neo_2010 in forum Java Programming Tutorials
    Replies: 3
    Last Post: July 8th, 2009, 11:38 AM