Results 1 to 8 of 8
  1. #1
    FOUAD-SPIDER is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default Change the signatures of the conflicting methods in generic class ?

    Hi there, I have this question and I really need the answer, I really don't understand anything in generics at all

    Here is the question:


    Generic parameters are not included in the signature of a method declaration, so you cannot have different methods in the same class that have different generic parameters but otherwise have the same names and the types and number of their parameters. How can you change the signatures of the conflicting methods to get around this restriction?
    I hope someone could help me ^^

    Thanks in advance!

  2. #2
    FOUAD-SPIDER is offline Member
    Join Date
    Feb 2011
    Posts
    4
    Rep Power
    0

    Default

    Here is a hint I found it somewhere:

    Look at how the java.util.Scanner class does it.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    If you know nothing about generics it's rather hard to see how anybody could even begin to answer in a way you would find enlightening.

    But, frankly, it looks like a request-for-homework-solution. I might be wrong and I hope I am: so what did you find in the Scanner source? (src.zip whereever your jdk is installed contains the file you are looking for). Was there even an example of the sort of situation you are talking about?

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    This won't help you understand generics (and you'll need to study and understand generics to fully answer the question), but notice that java.util.Scanner has a bunch of methods such as nextInt(), nextFloat(), nextDouble() etc.

    -Gary-

  5. #5
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Now I'm intrigued: why don't you offer us $1 the way you did at "Student of Fortune"? Because you rate us as more noble than those pond scum? Or merely the thought that such a miserly offer might elicit a less than friendly response?

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    I can't get at p146 of the book where that comes from (Google is proving uncooperative), but Scanner doesn't seem to have much generic about it. What gcalvin says is one way around the problem, another seems nicely illustrated in the java.lang.Enum class.

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

    Default

    Quote Originally Posted by pbrockway2 View Post
    Now I'm intrigued: why don't you offer us $1 the way you did at "Student of Fortune"? Because you rate us as more noble than those pond scum? Or merely the thought that such a miserly offer might elicit a less than friendly response?
    I can honestly say that you, pbrockway, are worth at least $2. Don't accept a penny less!

  8. #8
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    $2?

    Surely you jest! Isn't that "rep power" thingee the current the $/answer rate?

    I answer. I check my paypal account. Is this site broken??!?

    It's no good, you know, using your supermoderator powers to crank up your own earnings while leaving the rest of us to battle the forces of PBR unrewarded at even the more humble rate we accept as our lot.

Similar Threads

  1. How to check instance of a generic class?
    By chan_nguyen in forum New To Java
    Replies: 7
    Last Post: 09-08-2010, 05:20 AM
  2. Generic methods
    By andre1011 in forum Advanced Java
    Replies: 7
    Last Post: 02-25-2009, 03:17 PM
  3. Replies: 1
    Last Post: 05-17-2008, 12:06 AM
  4. A simple generic class
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-17-2008, 08:41 PM
  5. Writing generic methods
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-31-2007, 04:28 AM

Posting Permissions

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