dimanche 14 juin 2020

Language vs class-level reflection

I was reading this article when I stumbled on two terms: language reflection and class-level reflection:

When I lamented about this on Twitter, Brian Goetz picked up on it and explained that I was trying to do language-level reflection. Instead, I should see it as class-level reflection. This is true, of course. If I had written List.class.getMethod("size") all of the list objects would have happily volunteered their size.

Can you tell me, what the difference between those two is and what does it have to do with the following code raising IllegalAccessException:

Collection<String> col = List.of("Goetz", "Marks", "Rose");
col.getClass().getMethod("size").invoke(col);




Aucun commentaire:

Enregistrer un commentaire