wood burning stoves*
The moose likes Beginning Java and the fly likes Problem in using Method overloading in a class ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in using Method overloading in a class ?" Watch "Problem in using Method overloading in a class ?" New topic
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.

GenRocket - Experts at Building Test Data
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

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 - OCEEJBD 6
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
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You're welcome.
 
jQuery in Action, 2nd edition
 
subject: Problem in using Method overloading in a class ?
 
Similar Threads
Need rules for overloading please
Could you please explain the following code?
Role of Exceptions in overriding a method
Not able to send mail using SMTPTransport
method overloading issues