Created
November 21, 2013 14:18
-
-
Save KengoTODA/7582264 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.List; | |
| /** | |
| * @see https://twitter.com/cobot_1/status/403501394528718848 | |
| */ | |
| public class Example { | |
| static abstract class Dto {} | |
| static class DtoA extends Dto {} | |
| static class DtoB extends Dto {} | |
| static interface Dao<T extends Dto> { | |
| List<T> load(); | |
| } | |
| static class DaoA implements Dao<DtoA> { | |
| @Override | |
| public List<DtoA> load() { | |
| return new ArrayList<DtoA>(); | |
| } | |
| } | |
| static class DaoB implements Dao<DtoB> { | |
| @Override | |
| public List<DtoB> load() { | |
| return new ArrayList<DtoB>(); | |
| } | |
| } | |
| public static void main(String[] args) { | |
| List<Dao<? extends Dto>> daoList = Arrays.asList(new DaoA(), new DaoB()); | |
| for (Dao<? extends Dto> dao : daoList) { | |
| List<? extends Dto> values = dao.load(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment