Results 1 to 5 of 5
Thread: Java Generics
- 04-30-2011, 10:33 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
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 ??
- 04-30-2011, 11:19 PM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
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.)
- 05-01-2011, 12:21 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 9
- Rep Power
- 0
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 02:19 AM.
- 05-05-2011, 06:59 AM #4
Member
- Join Date
- May 2011
- Posts
- 3
- Rep Power
- 0
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.
- 05-05-2011, 07:11 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Please don't bump an old thread. Make a new thread with your question.
Similar Threads
-
java generics implementation
By sardare in forum Advanced JavaReplies: 1Last Post: 01-14-2010, 01:51 AM -
Generics in java
By ajeeb in forum Advanced JavaReplies: 5Last Post: 01-23-2009, 04:56 PM -
Question about java generics
By Arrowx7 in forum New To JavaReplies: 1Last Post: 08-14-2008, 02:37 AM -
Java confused over Generics?
By Bibendum in forum New To JavaReplies: 3Last Post: 12-26-2007, 06:23 AM -
Java Generics (an introduction)
By Java Tutorial in forum Java TutorialReplies: 0Last Post: 11-27-2007, 06:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks