| Author |
Problem in using Method overloading in a class ?
|
Vinod Vinu
Ranch Hand
Joined: Aug 30, 2009
Posts: 217
|
|
hi, iam implementing the concept of method overloading in java class but not able to succeed b'coz it is keep on saying that
'sendPrListToScreen' is undefined for the type 'service class name'.
But as per my knowledge it is defined.
But when i use two different names of this method declared above then it works perfectly but iam not able to use the cream of Core Java.
any suggestions?
thank you
|
Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
|
 |
Gregg Bolinger
Sheriff
Joined: Jul 11, 2001
Posts: 15040
|
|
What you're describing and what you've shown aren't adding up, for me. The problem is your use of Generics. As far as the compiler is concerned during this sweep, the 2 methods are the same. You should be getting an error about duplicate method names. Something along the lines of:
name clash: sendPrListToScreen(List<PrDraftHeader> prDraftList) and sendPrListToScreen(List<PurchaseRequestHeader> prList) have the same erasure
Also, an administrative note. Please use real words. Because instead of b'coz. We have a lot of users who's first language isn't English. By using words like b'coz it just makes it more difficult to communicate.
|
My Blog | DZone Articles
|
 |
Vinod Vinu
Ranch Hand
Joined: Aug 30, 2009
Posts: 217
|
|
The problem is your use of Generics. As far as the compiler is concerned during this sweep, the 2 methods are the same. You should be getting an error about duplicate method names.
i want to know that why the Generic lists cannot be used in Method Overloading in java ?
Is there an alternate solutions for it so that my purpose can resolved using method overloading ?
thank you once again
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 11642
|
|
Vinod Vijay wrote:i want to know that why the Generic lists cannot be used in Method Overloading in java ?
That's because of the way generics are implemented in Java - with type erasure
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Rob Spoor
Saloon Keeper
Joined: Oct 27, 2005
Posts: 18365
|
|
Type erasure removes all generics when a class is compiled. What remains is this:
They are very much the same.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Vinod Vinu
Ranch Hand
Joined: Aug 30, 2009
Posts: 217
|
|
|
thank you so much Jesper Young and Rob Prime for your support
|
 |
Rob Spoor
Saloon Keeper
Joined: Oct 27, 2005
Posts: 18365
|
|
|
You're welcome.
|
 |
 |
|
|
subject: Problem in using Method overloading in a class ?
|
|
|