RFR 8186961 Class.getFields() does not return fields of previously visited super interfaces/classes.

Paul Sandoz paul.sandoz at oracle.com
Thu Nov 30 22:25:29 UTC 2017

> On 30 Nov 2017, at 13:00, Claes Redestad <claes.redestad at oracle.com> wrote:
> Hi,
> as expected this is quite a bit easier to follow. Thanks!
> As any heavy use of reflection is likely to hit cached data, then heavily optimizing might be ill-advised here.
> A simpler optimization might be to check if the class has any superclass or interfaces whatsoever first, since if not then publicFields == privateGetDeclaredField(true). This might reduce number of LinkedHashSets created for many trivial class hierarchies significantly for only a nominal increase in code complexity, and actually reduce the retained set a bit.

I am resisting the temptation to do that right now, i threw away a highly optimal implementation, i liked it, but you might not :-) An intermediate solution is to create a pre-sized Field[][] and not be as smart about that allocation.

Mandy is gonna take a careful look next week.


More information about the core-libs-dev mailing list