This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics Declration doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics Declration doubt" Watch "Generics Declration doubt" New topic

Generics Declration doubt

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

  • ArrayList<?> and ArrayList<? extends Object>

  • How are these identical ? i understand here that first syntax means anything is possible and second means Object type only or its super class type but not anything then how are they identical ?

  • The wildcard syntax keyword extends is used to mean either "extends" or "implements". So in <? extends Dog> ,Dog cab be a class or an interface.

  • I understand this with class but i don't know how with interface please give me an example.thanks

    Tell the difficulties that i am difficult.
    Anayonkar Shivalkar

    Joined: Dec 08, 2010
    Posts: 1545

    saloni jhanwar wrote:i understand here that (1) anything (2) Object or it's super class

    No. The second argument means anything which extends Object - i.e. Object, or its subclass.

    saloni jhanwar wrote:So in <? extends Dog> ,Dog cab be a class or an interface.

    Yes, but it is reference type, right? I mean, when you pass a parameter to a method, you may pass a reference type of Dog, but it also would be referring to a concrete object (i.e. the class name which you used after 'new' keyword). And since that is an actual object (of a concrete class), that class would be implicitly sub-class of Object, right?

    I hope this helps.

    Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
    I agree. Here's the link:
    subject: Generics Declration doubt
    It's not a secret anymore!