title: bad return type in lambda expression cannot convert Object to T
body: <p>I have this lazy iterator that pretty much receives a function and a string as parameters, goes to an API, receives a DTO from the API and converts that DTO to a domain object (in this case an Event). This Event, as seen below is made up of an Artist and several Tracks. My problem (not only here) is that, when in my EventIterator, I try to populate my artistSupplier by passing a lambda expression, I get the error "Bad return type in lambda expression ArtistDto cant be converted to T".</p>
  
  <pre><code>public class EventIterator&lt;T, U, R&gt; extends SetListIterator&lt;T, U, R&gt; implements Iterator&lt;R&gt; {
  
  private Function&lt;U, T[]&gt; function;
  private String s;
  private LastfmApi lastfmApi;
  
  public EventIterator(String s, Function&lt;U, T[]&gt; function, LastfmApi lastfmApi) {
      this.lastfmApi = lastfmApi;
      this.s = s;
      this.function = function;
      page = 1;
  }
  
  @Override
  public R convertToDomainType(T[] ret) {
      EventDto [] eventDtos = (EventDto[]) ret;
      LinkedList list = new LinkedList&lt;Event&gt;();
      for (EventDto e:
           eventDtos) {
          Event event = new Event(
                  e.getArtistName(),
                  e.getEventDate(),
                  e.getTour(),
                  e.getTracksNames(),
                  getTracks(e.getTracksNames(), e.getArtistName()),
                  e.getSetListId()
           );
          event.setArtistSupplier(
                  (b, c) -&gt; new ArtistIterator&lt;R, U, T&gt;(
                          e.getArtistName(),
                          (a) -&gt; lastfmApi.getArtistInfo(e.getArtistName())
                  )
          );
          list.add(event);
      }
      return (R) list;
  }
  
  
  public class Event {
  
  private Artist artist;
  private Function&lt;String, Artist&gt; artistSupplier;
  private String artistName;
  private String eventDate;
  private String tour;
  private String [] tracksNames;
  private Iterable&lt;Track&gt; tracks;
  private String setlistId;
  
  public void setArtistSupplier(Function&lt;T, U&gt; supplier) {
      this.artistSupplier = supplier;
  }
  
  public Artist artist(String s) {
      return artist = (Artist) artistSupplier.apply((T) s);
  }
  
  }
  
  public class Artist {
  
  private String name;
  private String bio;
  private String url;
  private String [] imagesUri;
  private String mbid;
  
  }
  
  public abstract class SetListIterator&lt;T, U, R&gt; implements Iterator&lt;R&gt; {
  
  protected String s;
  protected int page;
  protected T []dtos;
  
  @Override
  public R next() {
      T[] ret = dtos;
      if (!hasNext())
          throw new NoSuchElementException();
      dtos = moveNext();
      return convertToDomainType(ret);
  }
  
  public abstract T[] moveNext();
  
  public abstract R convertToDomainType(T[] ret);
  }
  </code></pre>