You have a good point here.
Maybe we do your suggestion first, and then flail about with the other if we have no luck...
geir
> -----Original Message-----
> From: jeff [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 06, 2001 3:51 PM
> To: [EMAIL PROTECTED]
> Subject: Foreach.java contains questionable assumptions
>
>
> And I am the one to question those assumptions :)
>
> There is code which tests for the type of the container
>
> else if
> (Introspector.implementsMethod(listObject, "iterator"))
> type = INFO_ITERATOR;
> else if
> (Introspector.implementsMethod(listObject, "values"))
> type = INFO_MAP;
>
> and then code which uses this information to make type casts
>
> case INFO_ITERATOR :
> if (((Collection) listObject).size() == 0)
> return null;
> return ((Collection) listObject).iterator();
> ...
> case INFO_MAP:
> if (((Map) listObject).size() == 0)
> return null;
> return ((Map) listObject).values().iterator();
>
> The problem is that the tests don't guarantee the type of
> listObject and
> so these casts may throw.
>
> Is there some reason why the test section doesn't look like
> the following?
>
> else if ( listObject instanceof Collection )
> type = INFO_ITERATOR;
> else if ( listObject instanceof Map )
> type = INFO_MAP;
>
