using getter with java generic method argument

공부는 혼자하는 거·2021년 8월 22일
0

JAVA & Kotlin Tip

목록 보기
1/11

Have A and B implement a common interface that has a method getID:

interface SomeInterface {
    String getID();
}

then you could have:

private <T extends SomeInterface> void testMethod(List<T> list) {
    for (T event : list) {
        // now you can use `event.getID()` here
    }
}

https://stackoverflow.com/questions/13710954/using-getter-with-java-generic-method-argument

profile
시간대비효율

0개의 댓글