Community
Participate
Working Groups
Build Identifier: Build id: 20110916-0149 Defining a closure as a parameter of a method leads to a compile error in the generated java code. Reproducible: Always Steps to Reproduce: Sample Xtend2 File: import java.util.ArrayList import java.util.List class XtendCheck { def test() { val foos = new ArrayList<String>() // add some Foos foos.expand(s|s.empty) } def expand(List<String> list, (String) => Boolean filter) { val filteredList = list.filter(filter) } } Error: The parameterized method <String>filter(Iterable<String>, Functions.Function1<? super String,Boolean>) of type IterableExtensions is not applicable for the arguments (List<String>, Functions.Function1<capture#5-of ? super String,capture#6-of ? extends Boolean>)
Workaround: use Functions$Function1<Property,Boolean> as Type of the Closure
Resolved. Produced Java code is import java.util.ArrayList; import java.util.List; import org.eclipse.xtext.xbase.lib.Functions.Function1; import org.eclipse.xtext.xbase.lib.IterableExtensions; @SuppressWarnings("all") public class XtendCheck { public void test() { ArrayList<String> _arrayList = new ArrayList<String>(); final ArrayList<String> foos = _arrayList; final Function1<String,Boolean> _function = new Function1<String,Boolean>() { public Boolean apply(final String s) { boolean _isEmpty = s.isEmpty(); return Boolean.valueOf(_isEmpty); } }; this.expand(foos, _function); } public void expand(final List<String> list, final Function1<? super String,? extends Boolean> filter) { final Iterable<String> filteredList = IterableExtensions.<String>filter(list, (Function1<? super String,Boolean>)filter); } }
Requested via bug 522520. -M.