On Thu, 25 Mar 2021 17:30:52 GMT, Daniel Fuchs <[email protected]> wrote:
> This RFE proposes to extend the MXBean framework to define a mapping to
> records.
>
> The MXBean framework already defines a mapping of `CompositeType` to plain
> java objects. Records are a natural representation of CompositeTypes. A
> record can be easily reconstructed from a `CompositeData` through the record
> canonical constructor. A clear advantage of records over plain java objects
> is that the canonical constructor will not need to be annotated in order to
> map composite data property names to constructor parameter names.
>
> With this RFE, here is an example comparing coding a composite type
> `NamedNumber` that consists of an `int` and a `String`, using records and
> using a plain java class. In both case, the `CompositeType` looks like this:
>
> CompositeType(
> "NamedNumber", // typeName
> "NamedNumber", // description
> new String[] {"number", "name"}, // itemNames
> new String[] {"number", "name"}, // itemDescriptions
> new OpenType[] {SimpleType.INTEGER,
> SimpleType.STRING} // itemTypes
> );
>
> The plain Java class needs a public constructor annotated with
> `@ConstructorParameters` annotation:
>
> public class NamedNumber {
> public int getNumber() {return number;}
> public String getName() {return name;}
> @ConstructorParameters({"number", "name"})
> public NamedNumber(int number, String name) {
> this.number = number;
> this.name = name;
> }
> private final int number;
> private final String name;
> }
>
> And the equivalent with a record class:
>
> public record NamedNumber(int number, String name) {}
src/java.management/share/classes/javax/management/MXBean.java line 792:
> 790: accessor for a record component {@code name} of type <em>T</em>,
> 791: then the item in the {@code CompositeType} has the same name
> 792: than the record component, and has type <em>opentype(T)</em>.</p>
The update to the MXBean spec looks good. Do you have a typo here, I assume it
should say "as the record component".
-------------
PR: https://git.openjdk.java.net/jdk/pull/3201