Results 1 to 5 of 5

Thread: Java Generics

  1. #1
    learn2java is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Exclamation Java Generics

    :(:(:(:(:(:(:(:(:(


    Hi ,

    Can some one explain in java generics , if beta extends alpha , a variable of type alpha may refer to an object of type beta , a variable of type list <Alpha> may refer an object of type Arraylist<Alpha>, but a variable of typelist<Alpha> may refer an object of type Arraylist<Beta>, Can some one tell exactly what happens in it or what is this case ??

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    a variable of typelist<Alpha> may refer an object of type Arraylist<Beta>

    I get "Type mismatch: cannot convert from ArrayList<Test.Beta> to List<Test.Alpha>" when I try this.

    Java Code:
    import java.util.ArrayList;
    import java.util.List;
    
    public class Test {
        class Alpha {}
        class Beta extends Alpha {}
    	
        public static void main(String[] args){
            List<Alpha> test = new ArrayList<Beta>();
        }
    }

    Did you mean a variable of type List<Alpha> may not refer an object of type ArrayList<Beta>? (If not post a SSCCE showing what you did mean).

    -----

    The compiler message above is explained on the Subtyping page of Oracle's Generics Tutorial. Post if you don't understand the point they make there (that a specific sort of butterfly cage is not good as a general purpose animal cage because it might well be too flimsy.)

  3. #3
    learn2java is offline Member
    Join Date
    Apr 2011
    Posts
    9
    Rep Power
    0

    Default

    hi pbrockway2 ,

    In your last statement you are exactly right , I mean the same but I can not understand the concept of it , pls can you tell in detail and explain about it ?
    Last edited by learn2java; 05-01-2011 at 03:19 AM.

  4. #4
    anbu.gn is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Post About RAD IDE for Java

    Hi All
    I'm new to RAD IDE. can any one explain me how to import the project in to the IDE.

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

Similar Threads

  1. java generics implementation
    By sardare in forum Advanced Java
    Replies: 1
    Last Post: 01-14-2010, 02:51 AM
  2. Generics in java
    By ajeeb in forum Advanced Java
    Replies: 5
    Last Post: 01-23-2009, 05:56 PM
  3. Question about java generics
    By Arrowx7 in forum New To Java
    Replies: 1
    Last Post: 08-14-2008, 03:37 AM
  4. Java confused over Generics?
    By Bibendum in forum New To Java
    Replies: 3
    Last Post: 12-26-2007, 07:23 AM
  5. Java Generics (an introduction)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 11-27-2007, 07:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •