[lworld] RFR: 8245584: [lworld] LW3 core reflection update

Mandy Chung mandy.chung at oracle.com
Tue May 26 18:59:36 UTC 2020



On 5/25/20 12:40 PM, Remi Forax wrote:
> [CC to Brian and amber-dev] because this is relevant to the API around record too.
>
> ----- Mail original -----
>> De: "John R Rose" <jrose at openjdk.java.net>
>> À: "valhalla-dev" <valhalla-dev at openjdk.java.net>
>> Envoyé: Samedi 23 Mai 2020 20:51:14
>> Objet: Re: [lworld] RFR: 8245584: [lworld] LW3 core reflection update
>> One comment, really for the future, regarding the shape of the Java API here:
>> It uses Optional and omits the "get"
>> prefix on accessors.  This is the New Style, as opposed to the Classic Style
>> using null (for "empty" results) and a
>> "get" prefix ("getComponentType") to get a related type.  We may choose to to
>> use the New Style for new reflection API
>> points, and if so let's not choose N different New Styles, but one New Style.
>> Personally I like removing "get"; I
>> accept Optional instead of null; and I also suggest that arrays (if any) be
>> replaced by (immutable) Lists in the New Style.
> Please no, no New Style if the Old Style is good enough,
> as a user i don't want to care if something was created a long ago or recently, if the API uses "get", or not, consistency is more important,
> because it creates the feeling that you understand how the API works.
>
> I think NetworkInterface [1] is the perfect example of how to evolve an API,
> because it contains a mix between old, very old and new style.
>
> 1/ you have Enumeration used instead of Iterator because it's coherent with the java.net package that was created for Java 1, even if NetworkInterface was introduced in Java 4.
>     even methods introduced in Java 6 uses Enumeration.
> 2/ recently some methods that returns a Stream were added.
>
> I see two rules, one is when you grow an API follow the style of the API and if you have a good reason to introduce an API points with a new style, then provide both variants the old way and the new way.

IMO, adding both old way and the new way bloats the API unnecessarily.

Note that the java.lang.Class API implements TypeDescriptor.ofField 
which already introduces the new style APIs, Class::describeConstable 
and Class::arrayType etc.

Mandy
> regards,
> Rémi
>
> [1] https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/net/NetworkInterface.html
>



More information about the valhalla-dev mailing list