This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: function parameters with generic types


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]