On Mon, 1 Aug 2022 23:05:58 GMT, Joe Darcy <da...@openjdk.org> wrote:
>> Probably by creating and using shared instances of `java.util.Function` >> which would also allow deduplicating the code. > >> Is there another way to implement this that does not create 19 anonymous >> classes with a single overloaded method? > > Overriding a method in an enum constant specific class is one way to > implement constant-specific behavior. Textually, I thought it had the > advantage of having the class file version specific behavior close to the > latest version behavior. > > This could be refactored in various ways, such as having > AccessFlag.locations(ClassFileFormatVersion cffv) start with a switch over > the location which implemented the enum constant specific behavior. Or the > set of parameters of the enum constructor could be augmented to cover more > cases (empty until $VERSION, then $LOCATIONS, etc.), with constant-specific > overrides just constants with unique patterns like STRICT. True, many ways to factor the code. Another possibility is add a field to the enum that holds a `java.util.Function<Iteger, Set<Location>>)` and initialize it each with a lambda of the code now in the locations(cffv) method that maps the cffv to the set of locations. ------------- PR: https://git.openjdk.org/jdk/pull/9299