Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Generics

  1. #1
    Fatz is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Default Generics

    Hi, i am writing a program which has to use generics,
    what i want is the arraylist to contain object (methods) from another class. Is there anyway to do this?

    I know for vectors i would just use elementAt(i).MethodFromOtherClassName();

    But this is not the case here.

    Any suggestions?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Generics

    Quote Originally Posted by Fatz View Post
    Hi, i am writing a program which has to use generics,
    what i want is the arraylist to contain object (methods) from another class. Is there anyway to do this?
    Please clarify what you're trying to do as that statement above is confusing. ArrayLists hold objects, not methods. You can call methods on the objects it holds. What have you tried and what isn't working or what *specifically* confuses you?

  3. #3
    Fatz is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Default Re: Generics

    Yes sorry, ArrayLists that hold objects.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Generics

    Quote Originally Posted by Fatz View Post
    Yes sorry, ArrayLists that hold objects.
    OK, so again what have you tried and where are you stuck?

  5. #5
    Fatz is offline Member
    Join Date
    May 2012
    Posts
    12
    Rep Power
    0

    Default Re: Generics

    I am trying to write a program which takes as an argument, an array list of student objects (student is a class). if the array list b contains three objects of the student class it will print the names of the student who's marks are greater than 20.0.
    for example, joe 20 , jack 15 and lucy 21 will print joe Lucy.

    what i'm stuck on is accessing the marks and names method from the students class. so the comparisons can be made.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Generics

    Quote Originally Posted by Fatz View Post
    I am trying to write a program which takes as an argument, an array list of student objects (student is a class). if the array list b contains three objects of the student class it will print the names of the student who's marks are greater than 20.0.
    for example, joe 20 , jack 15 and lucy 21 will print joe Lucy.

    what i'm stuck on is accessing the marks and names method from the students class. so the comparisons can be made.
    What I'm getting at is, please show us your code attempt to solve this. This is the best way for us to see what you're doing wrong and then be able to help you.
    DarrylBurke likes this.

Similar Threads

  1. Generics
    By pepe34 in forum Advanced Java
    Replies: 0
    Last Post: 10-30-2011, 11:31 PM
  2. Using Generics
    By darshanaprasad in forum New To Java
    Replies: 7
    Last Post: 06-10-2011, 12:20 AM
  3. generics
    By arik23 in forum New To Java
    Replies: 2
    Last Post: 04-21-2011, 05:28 PM
  4. Generics
    By sakshamkum in forum Advanced Java
    Replies: 3
    Last Post: 06-03-2010, 11:12 PM
  5. Generics
    By bschmitt78 in forum Advanced Java
    Replies: 3
    Last Post: 03-16-2010, 03:21 AM

Tags for this Thread

Posting Permissions

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