Friday, January 27, 2017

References to Class method works incorrectly

Hi,

I have in code the following lines (few of `Panel` classes implements `TagAware` interface):

```Java
private final Map<PanelType, Panel<T>> panels;
//...
panels
.values()
.stream()
.filter(TagAware.class::isInstance)
.map(TagAware.class::cast)
.forEach(t -> t.setTagsWorkHours(this.tagsWorkHours));
```
The code perfectly compile by javac, but not with GWT compiler: 

      Errors in 'file:/C:/Development/work/repo/JRS/open/gxt/calendar/widget/src/main/java/org/jresearch/gwt/client/date/widget/Calendar.java'
         Line 376: The type Class<TagAware> does not define isInstance(Panel<T>) that is applicable here
         Line 376: The method filter(Predicate<? super Panel<T>>) in the type Stream<Panel<T>> is not applicable for the arguments (TagAware.class::isInstance)

The same with cast

      Errors in 'file:/C:/Development/work/repo/JRS/open/gxt/calendar/widget/src/main/java/org/jresearch/gwt/client/date/widget/Calendar.java'
         Line 377: The method map(Function<? super Panel<T>,? extends R>) in the type Stream<Panel<T>> is not applicable for the arguments (TagAware.class::cast)
         Line 377: The type Class<TagAware> does not define cast(Panel<T>) that is applicable here


##### Known workarounds

Rewrite the above lines without method references:

```Java
panels
.values()
.stream()
.filter(p -> p instanceof TagAware)
.map(p -> (TagAware) p)
.forEach(t -> t.setTagsWorkHours(this.tagsWorkHours));
```

Best,
Stas

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment