Results 1 to 8 of 8
- 02-26-2011, 11:10 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
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:
I hope someone could help me ^^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?
Thanks in advance!
- 02-26-2011, 11:28 PM #2
Member
- Join Date
- Feb 2011
- Posts
- 4
- Rep Power
- 0
Here is a hint I found it somewhere:
Look at how the java.util.Scanner class does it.
- 02-27-2011, 12:07 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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?
- 02-27-2011, 12:08 AM #4
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
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-
- 02-27-2011, 12:21 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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?
- 02-27-2011, 12:32 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
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.
-
- 02-27-2011, 01:17 AM #8
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
$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
-
How to check instance of a generic class?
By chan_nguyen in forum New To JavaReplies: 7Last Post: 09-08-2010, 04:20 AM -
Generic methods
By andre1011 in forum Advanced JavaReplies: 7Last Post: 02-25-2009, 02:17 PM -
The type Class is not generic; it cannot be parameterized with arguments <T>
By new_2_java in forum Advanced JavaReplies: 1Last Post: 05-16-2008, 11:06 PM -
A simple generic class
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:41 PM -
Writing generic methods
By eva in forum New To JavaReplies: 2Last Post: 12-31-2007, 03:28 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks