Maybe use GeoTools converters here too in order to match the classes of nearest value and matchedValue. I'd go, if possible, for turning the matchedValue into the type associated to the attribute (which can be derived from the featureType of the collection, before passing in the visitor) and then do all the work in uniform types.