This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Multiple possible matches for constructor
- From: Per Bothner <per at bothner dot com>
- To: Mark Wutka <mark at wutka dot com>
- Cc: kawa at sourceware dot org
- Date: Wed, 11 Jan 2006 16:36:45 -0800
- Subject: Re: Multiple possible matches for constructor
- References: <20060112035342.GA12707@wutka.com>
Mark Wutka wrote:
I was trying to write a little function to open a socket and return an
input port and an output port as values. It seems to work, but
originally I was getting warnings about multiple possibly applicable
methods, since Socket can take InetAddress or String as the first
parameter. The only way I could find to eliminate the warning was to use
(primitive-constructor <java.net.Socket> (<java.lang.String> <int>))
Use a cast or a type specifier. I suggest:
(define (socket-connect (host :: <String>) (port :: <int>))
...)
What I am wondering is, does it really matter? The original code that
just called java.net.Socket:new seems to work just fine, I just don't
know if one is any more efficient than the other.
It makes a big difference. If you get the warning, it means Kawa cannot
pick the right methods at compile-time, but instead has to use run-time
reflection, which is a *lot* slower.
Also, many of these warnings may be due to a bug in your program, so it
is definitely worthwhile trying to fix them. Also, you might consider
compiling with --warn-undefined-variable which catches even more errors.
I guess if I leave it the old way, my function can take either String or
InetAddress as a parameter.
That is true, but if you want that it's more efficient (if you care)
to do the test yourself:
(if (instance? host <java.net.InetAddress>))
(java.net.Socket:new (as <java.net.InetAddress> host) port)
(java.net.Socket:new (as <String> host) port))
--
--Per Bothner
per@bothner.com http://per.bothner.com/