dimanche 25 octobre 2020

How can I use reflection in the Lambda expression in Java stream?

I want to make it a common fuction to filter a list using a java stream.
but it doesn't work out the way I want it to...

The code below doesn't work, but is it possible to filter using reflection within a lambda expression?

 List filterList = commonList.stream()
                .filter(x -> x.getClass().getDeclaredField("metadata").get(this)
                .getClass().getDeclaredField("name").get(this).matches(keywords))
                .collect(Collectors.toList());




Aucun commentaire:

Enregistrer un commentaire