This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
RE: function parameters with generic types
- From: "Dominique Boucher" <dominique dot boucher at nuecho dot com>
- To: "'Hurst, Dave'" <DHurst at lisletech dot com>, <kawa at sources dot redhat dot com>
- Date: Wed, 19 Jul 2006 09:28:17 -0400
- Subject: RE: function parameters with generic types
- Reply-to: <dominique dot boucher at nuecho dot com>
Dave,
> I have a Java class that has an overloaded method. The two
> methods are
> distinguished by the argument types.
>
> class PolicyFilter {
> public List<PolicyNode> filter(PolicyNode p);
> public List<PolicyNode> filter(List<PolicyNode> p);
> }
>
> When I call one of these methods from Kawa, I get an error
> complaining that
> there is "no definitely applicable method 'filter' in
> PolicyFilter." So I
> defined a utility function that specifies the type of its arguments.
>
> (define (filter-policy policy :: <java.util.List>)
> (PolicyFilter:filter policy)
> ... )
This function will raise an exception when invoked. You shall specify the
PolicyFilter object:
(define (filter-policy policy-filter :: <PolicyFilter> policy ::
<java.util.List>)
(PolicyFilter:filter policy-filter policy)
...)
I guess it's simply a bad cut&past on your part ;-)
An alternative to defining a new function is simply to introduce a typed
local variable:
(let ((policy :: <java.util.List> (...)))
(PolicyFilter:filter policy-filter policy))
...)
or cast the policy object:
(PolicyFilter:filter policy-filter (as <java.util.List> policy))
Hope this helps!
Dominique