[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-openjfx-dev
Subject:    Re: JavaBeanObjectPropertyBuilder has incomplete generics support
From:       Nir Lisker <nlisker () gmail ! com>
Date:       2018-11-20 5:52:20
Message-ID: CA+0ynh9gEtV4x+MzASMOT_d0u6DVYtXs=E=C9y7zoUMdTgbNJg () mail ! gmail ! com
[Download RAW message or body]

This is simple enough, but I think it breaks backwards compatibility at the
API level. Warnings about raw types are common in the library, though most
are internal.

If this is somehow allowed I can easily submit a patch.

- Nir

On Fri, Nov 2, 2018 at 3:27 PM Rachel Greenham <rachel@merus.eu> wrote:

> javax.beans.property.adapter.JavaBeanObjectPropertyBuilder seems to be
> only partially adapted for generics. The class itself has a generic type
> (class JavaBeanObjectPropertyBuilder<T>) and its build() method returns
> JavaBeanObjectProperty<T>, but the lack of other support means you can't
> fluently create a property without also suppressing "unchecked" warnings.
>
> ie: One might want to do:
>
> private ObjectProperty<Inet4Address> ip4Property;
>
> ...
>
> this.ip4Property = JavaBeanObjectPropertyBuilder.create()
>      .bean(server)
>      .name("ip")
>      .build();
>
> but this will produce "unchecked" warnings during compilation. Harmless
> but annoying when you want to keep it clean. As it stands, to compile
> cleanly you need to split it up:
>
> var builder = new JavaBeanObjectPropertyBuilder<Inet4Address>();
> builder.bean(server).name("ip"); // they return untyped builder
> this.ip4Property = builder.build();
>
> ... or suppress the warning. I hate suppressing warnings. :-)
>
> Proposed fix: (I don't have an OpenJFX build environment yet, this is
> the first time I've wanted to change something!)
>
> * Each of the instance methods (except build()) to have declared return
> type JavaBeanObjectPropertyBuilder<T>. This allows chaining those fluent
> builder methods without losing the generic type.
>
> * create() method to be:
> public static <T> JavaBeanObjectPropertyBuilder<T> create() {
>      return new JavaBeanObjectPropertyBuilder<T>();
> }
>
> I think that's all it needs, and the latter only if you prefer to use
> the static builder factory method rather than just using the constructor
> directly. Then the first code example above would work cleanly as is. It
> also allows for callers to optionally explicitly specify the generic
> type to create() with eg: var builder =
> JavaBeanObjectPropertyBuilder.<Inet4Address>create().
>
> As you can see all this is just generic type declarations, which should
> all be erased to cause no actual change to runtime. The effect on
> existing code should be null except that some people would be able to,
> if they want, remove the @SuppressWarnings
> ("unchecked") annotation they've so far had to put above it.
>
> --
> Rachel
>
>
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic