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