aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Generics" Watch "Doubt in Generics" New topic
Author

Doubt in Generics

Rikesh Desai
Ranch Hand

Joined: Jun 02, 2010
Posts: 83
Source: http://www.angelikalanger.com/GenericsFAQ/FAQSections/ParameterizedTypes.html#FAQ001



I am not able to understand how the line marked in red (Line 1) is giving error?


OCPJP 95%
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9302
    
  17

The declaration of Name class given in the tutorial is

Since Name is a sub-class of Pair, you can't directly assign a super class object to a sub-class reference...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Rikesh Desai
Ranch Hand

Joined: Jun 02, 2010
Posts: 83
oh, I missed seeing that line!
Thank you Ankit for your quick response!

I am stuck at one more place..

same source:



Arrays holding elements whose type is a concrete parameterized type are illegal.


I am not able to understand the reason given by them for the same.
What is wrong in an array having elements whose type is a concrete parameterized type?
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

i am not sure if this is the problem but i guess you can't instantiate generic array.
see this.


SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
 
 
subject: Doubt in Generics