I am unable to turn the List returned by the getResultList() method into a List<SeedCalendarResultDTO> through mapping with stream. When i collect the result the collect method would supposedly return an Object instead of List<SeedCalendarResultDTO> and i don't understand why this is happening. In the doc i can read that getResultList returns an untyped List and not an object, so why does the collect method return an object then? Heres the relevant code snippet:
Query query = entityManager.createQuery(queryBuilder.toString());
Object collect = query.getResultList().stream()
.map(object -> (SeedCalendarResultDTO) object)
.collect(Collectors.toList());
I can't change Object collect to List collect because it creates a compile error. I don't want to use NamedQuery either because the query string is constructed dynamically.
EDIT: This works just fine for some reason, but undesirable because now it is still a list of objects. List<SeedCalendarResultDTO> results = query.getResultList();