• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in using Method overloading in a class ?

 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Type erasure removes all generics when a class is compiled. What remains is this:
They are very much the same.
 
Vinod Vinu
Ranch Hand
Posts: 217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much Jesper Young and Rob Prime for your support
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic