RFC: draft API for JEP 269 Convenience Collection Factories

Timo Kinnunen timo.kinnunen at gmail.com
Sat Oct 17 01:27:03 UTC 2015


Hi,
Calling a static method of a superclass using the name of the subclass is already a warming in any decently configured IDE. Fixing such warnings is so trivial that having displayed the warning an IDE could do it automatically. 
Such a code sample is not a convincing argument against static factory methods in concrete classes, it is simply an observation that such methods do not provide good support for bad code.
If there's any takeaway from such code it is this: improving an API in one place raises expectations for all such APIs. This is great, it means the improvements are real and should be applied in as many places as they can be, and no fewer.



Sent from Outlook




On Fri, Oct 16, 2015 at 4:18 PM -0700, "Remi Forax" <forax at univ-mlv.fr> wrote:










The other reason I see to avoid methods of on impelmentations is that as i've already said, Java allows to inherits static methods defined on class so adding a method of() on ArrayList will allow people to use of on a subclass of HashMap/ArrayList but did get the expected object, by example, LinkedHashMap.of() will return a HashMap.

so +1 to have methods of() only on interfaces.

Rémi

----- Mail original -----
> De: "John Rose" 
> À: "Kevin Bourrillion" 
> Cc: "core-libs-dev" 
> Envoyé: Mercredi 14 Octobre 2015 22:46:40
> Objet: Re: RFC: draft API for JEP 269 Convenience Collection Factories
> 
> On Oct 14, 2015, at 10:56 AM, Kevin Bourrillion  wrote:
> > Anyway, since we created these methods, they became an attractive nuisance,
> > and thousands of users reach for them who would have been better off in
> > every way using an immutable collection. Our fondest desire is to one day
> > be able to delete them. So, obviously, my strong recommendation is not to
> > add these to ArrayList, etc.
> 
> I agree with Kevin's warning here.  Please, (1) make the immutable version
> easy to get (List.of not ImmutableList.of), and require users to
> thoughtfully opt into mutability (new ArrayList not ArrayList.of).
> 
> — John


More information about the core-libs-dev mailing list