aspose file tools*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics Declration doubt" Watch "Generics Declration doubt" New topic
Author

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
    Bartender

    Joined: Dec 08, 2010
    Posts: 1510
        
        5

    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.


    Regards,
    Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Generics Declration doubt