Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Requried help in Generics

 
kaushik vira
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello ranchers,

Tomorrow i have Exam, still my confidence in Generics is not at desired level. so i decided to go though the book of [Java Generics and Collections - By Maurice Naftalin, Philip Wadler ].

but I am not able to understand the following program, can any buddy simplify the explanation of the program.

From book :- Java Generics and Collections - By Maurice Naftalin, Philip Wadler




If any buddy having better suggestion about generics, then please let me know.. before exam i will go though that content.. I want to break SCJP With more then 95% but exam score is not my Goal.. knowledge behind the score is imp..
 
kaushik vira
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it`s funny to reply own Thread.. but i found something good... which are sharable..

There is 2 basic rules in Generics :- From book - [Java Generics and Collections - By Maurice Naftalin, Philip Wadler ].

Substitution Principle: a variable of a given type may be assigned a value of any subtype of that type, and a method with a parameter of a given type may be invoked with an argument of any subtype of that type.

The Get and Put Principle: use an extends wildcard when you only get values out of a structure, use a super wildcard when you only put values into a structure, and don't use a wildcard when you both get and put.

also Good Thread..
http://www.coderanch.com/t/447368/Programmer-Certification-SCJP/certification/BIG-WITH-COllections-Generics#1990975

now i can understand extend and super wild card... Both made my life easy with Java...
 
Venkata Saraswathi
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Adding one more note to above is

As there is no equalent ArrayStoreException for Generics as exists for Arrays, It doesn't allow to add sub types.

have you done your exam? How difficult is it?

--Venkata.
 
kaushik vira
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It`s very easy then Exam lab.. my score is 74%.. but better we not discuss this on forum, we have "private message" option available here..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic