RFR: make FieldLayout#data() public

Ivan Ponomarev duke at openjdk.java.net
Thu Nov 11 00:00:01 UTC 2021


On Tue, 9 Nov 2021 17:33:59 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

> Maybe it would be better to provide the specific accessor, like:

You mean the accessor for `FieldData` class? Yeah it would be nice, but it will not be sufficient for us to have it on `FieldLayout` level (we need field's type `Class` etc.)

> maybe it would be even better to merge LJV into JOL

Well, definitely yes at some point... I use LJV as a playground for my students to teach them Java programming / opensource contributing and the project is being rewritten at the moment. When it stabilizes, I will try to merge it

> Can you pseudo-code or point the usage example?


for (FieldLayout fieldLayout : ClassLayout.parseClass(obj.getClass()).fields()) {
            Field f = fieldLayout.data().refField();

            Object v = ObjectUtils.value(obj, f); //primitives are wrapped, type information lost!

            //We need everything that can be extracted from Field...
            refField.getAnnotations()... //e.g. paint the field a specific color
            refField.getGenericType()... //e.g. label the field with type information

            if (refField.getType() is primitive or can be treated as primitive per LJV setup){
                //treat the value as primitive...

            } else {
                //walk further the object's graph...
            }
        }

-------------

PR: https://git.openjdk.java.net/jol/pull/19


More information about the jol-dev mailing list