• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generics Doubt

 
Ranch Hand
Posts: 182
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
19)Which call(s) to method(addandDisp) are error free? From JavaBeat

a)only 3
b)only 1 and 3
c)only 1 and 4
d)only 1,2 and 3
e)only 1,3 and 4

Given Answer : e
My Doubt : public static <T> void addandDisp(Collection<T> cs, T t)

Here Collection is of type T and second parameter also T. So I thought only 4 is Correct.


How can we send this :
Her els3 of type Object means in the method addandDisp() first parameter is T holds Object , How come second Orameter T holds String???

 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Her els3 of type Object means in the method addandDisp() first parameter is T holds Object , How come second Orameter T holds String???




A String IS-A Object.

Henry
 
Balaji Bang
Ranch Hand
Posts: 182
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Explanation given is : Method call 2 cannot work,because the compiler cannot gurantee the type to
substitute.But in all other calls it is guranteed.

I didn't understand this ..... Please..
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Banu Chowdary wrote:Explanation given is : Method call 2 cannot work,because the compiler cannot gurantee the type to
substitute.But in all other calls it is guranteed.

I didn't understand this ..... Please..



With the second option, T is an unknown type that may extends Object. T may not be an Object type, as required by the second parameter.

Henry
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic