Results 1 to 3 of 3

Thread: generics

  1. #1
    arik23 is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default generics

    I'm just not sure if I got right...

    if I write add method that look like this :
    add (<? extends E> e)
    each element in my collection could be from a different type (all of them extends E type (or from E itself)). right?

    now if I write remove method that looks like this :
    remove(Collection<?>) it won't be accept my collection because this is requires that all the elements in the given collection will be from the same type. am I right?

    will this be acceptable instead?
    remove(Collection<? extends E>)

    thank you

  2. #2
    makpandian's Avatar
    makpandian is offline Senior Member
    Join Date
    Dec 2008
    Rep Power


    Refer the Book SCJP by Kathy Sierra in chaper 7 page no 618 to 622.
    (Living @ Virtual World)

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power


    I suggest you also check out the oracle tutorials.
    Lesson: Generics (The Java™ Tutorials > Learning the Java Language)

    As far as I know, however; remove(Collection<?>) will remove the collection, where ? is the type in the collection. Since you can load a collection with any type that extends E, removing a collection works fine as remove(Collection<?>).

    I am, however; not especially experienced with generics. The tutorials will definitely provide you with a lot of useful information, and examples to illustrate everything.

Similar Threads

  1. generics
    By arik23 in forum New To Java
    Replies: 3
    Last Post: 04-19-2011, 11:31 AM
  2. Help with generics
    By shai in forum New To Java
    Replies: 0
    Last Post: 08-12-2010, 08:07 AM
  3. Generics
    By sakshamkum in forum Advanced Java
    Replies: 3
    Last Post: 06-03-2010, 11:12 PM
  4. Generics
    By bschmitt78 in forum Advanced Java
    Replies: 3
    Last Post: 03-16-2010, 03:21 AM
  5. generics
    By tascoa in forum Forum Lobby
    Replies: 2
    Last Post: 10-09-2008, 08:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts