Just start to learn and know about java reflection, would appreciate any help on this problem.
I'm trying to write a method and it looks like this:
private <T> void myMethod (List<T> testSub) {
testSub.forEach(s -> assertEquals(s.getSource(), "TEST"));
}
But it shows an error because java don't know if testSub's class has getSource() this method and it want me to cast s.getSource() to a known class.
What I want is to somehow let java know that the the itmes in testSub's class has this getSource() method and it could be invoked and safe to call.
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire