Java code is compiled. This means that any decisions regarding overloaded methods are
taken at compile time.
In your code you call private boolean validate(Tag tag, Object value), since the
"value" variable is is defined as having Object type. So the
code is binded to that function, regardles of the runtime type.
Paul
12.03.2002 13:02:16, Sourabh Kulkarni <[EMAIL PROTECTED]> wrote:
>
>
> Date: Tue, 12 Mar 2002 16:32:16 +0530
>
> From: Sourabh Kulkarni <[EMAIL PROTECTED]>
> Subject:OffTopic - strange overloaded method behaviour
> To: [EMAIL PROTECTED]
>
>
>
> Hi,
> This is a bit OffTopic. I have written following overloaded methods.
> private boolean validate(Tag tag, Object value)
>
> private boolean validate(Tag tag, Number value)
> private boolean validate(Tag tag, String value)
> private boolean validate(Tag tag, Boolean value)
>
> The invoking code is in the same class. The relevant part is given below
>
> Set set = valuesMap.entrySet();
>
> Iterator itr = set.iterator();
> String tagname, msg;
> Object value, tag;
> Map.Entry entry;
>
> Tag t;
> boolean valid;
> while (itr.hasNext()) {
> entry = (Map.Entry) itr.next();
>
> tagname = (String) entry.getKey();
> value = entry.getValue();
> tag = tagMap.get(tagname);
> file://if not null and valid, then remove it from the valuesMap and send
>
> for writing
> if ((tag != null) && (value != null) && validate((Tag) tag, value)) {
> file://do something
> }
>
>
> I am having an entry in the map as "name"=Float . At execution time, I
> expected the method validate(Tag, Number) to be invoked rather than
> validate(Tag, Object). But I observed that validate(Tag, Object) was
> invoked. I am confused by this behaviour. Am I missing something ?
>
>
> TIA,
> -sourabh
> ----
> Sourabh Kulkarni
>
> Embedded Systems Group.
> rapidEffect (P) Ltd.25,Napier Road, Pune 411 001
> Tel./Fax. +91-20-6363250
>
> www.rapideffect.com
----------------------------------------
Paul Balanoiu
Bucharest, Romania
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html