| Summary: | [Xtend2] problem with type inference | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Lieven Lemiengre <lieven.lemiengre> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | sebastian.zarnekow |
| Version: | 2.1.0 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | |||
This works as expected. The signature of EcoreUtil.getAllContents looks like this: <T> TreeIterator<T> getAllContents(Resource, boolean) thus you'd have to use Iterator<EObject> iter = EcoreUtil.<EObject>getAllContents(..) in Java where Xtend allows to use val iter = EcoreUtil::<EObject>getAllContents(..) or val Iterator<EObject> iter = EcoreUtil::getAllContents(..) (In reply to comment #1) > you'd have to use > > Iterator<EObject> iter = EcoreUtil.<EObject>getAllContents(..) > > in Java That was too fast. Java has inference for the type argument, too. E.g. the following is valid in Java and in Xtend: Iterator<EObject> iter = EcoreUtil.getAllContents(..) |
problem: class SomeSemanticHighlightingCalculator implements ISemanticHighlightingCalculator { override provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) { if(resource == null) return; val Iterator<EObject> iter = EcoreUtil2::getAllContents(resource, true) while(iter.hasNext) { highlight(iter.next, acceptor) } } } I have to explicitly type iter as 'Iterator<EObject>' otherwise the type 'Iterator<?>' is inferred.