Last active
May 14, 2018 13:48
-
-
Save lWeRl/65c7ab21685bb9e368955cedf212b2a7 to your computer and use it in GitHub Desktop.
Lambda & Generic error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
//java version "1.8.0_151" | |
//fix https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8142476 | |
public class LambdaGenHell { | |
interface IdEntity { | |
Long getId(); | |
} | |
static class Model {} | |
static class IdModel extends Model implements IdEntity { | |
private Long id; | |
public IdModel(Long id) { | |
this.id = id; | |
} | |
@Override | |
public Long getId() { | |
return id; | |
} | |
} | |
public static void main(String[] args) { | |
List<IdModel> list = Arrays.asList(new IdModel(1L), new IdModel(2L), new IdModel(3L)); | |
makeHell(list); //BootstrapMethodError | |
make(list); //Without error | |
} | |
static <T extends Model & IdEntity> List<Long> makeHell (List<T> list) { | |
return list.stream().map(IdEntity::getId).collect(Collectors.toList()); | |
} | |
static <T extends Model & IdEntity> List<Long> make (List<T> list) { | |
return list.stream().map(e -> e.getId()).collect(Collectors.toList()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment