Fleshgrinder commented on a change in pull request #9369: URL: https://github.com/apache/kafka/pull/9369#discussion_r508639180
########## File path: clients/src/main/java/org/apache/kafka/clients/consumer/OffsetResetStrategy.java ########## @@ -16,6 +16,40 @@ */ package org.apache.kafka.clients.consumer; +import java.util.Locale; +import java.util.Objects; + +/** + * @see ConsumerConfig#AUTO_OFFSET_RESET_CONFIG + * @see ConsumerConfig#AUTO_OFFSET_RESET_DOC + */ public enum OffsetResetStrategy { - LATEST, EARLIEST, NONE + LATEST, EARLIEST, NONE; + + // Enums are singletons, this means that this conversion happens once the + // first time a variant is actually used, and never again. + private final String id = name().toLowerCase(Locale.ROOT); Review comment: We can move the code to `toString` but than the `toLowerCase` conversion is executed every time `toString` is invoked. This way the conversion happens once: the first time the enum is used. From there on out the string stays and never needs to be recomputed. Meaning: ```java System.out.println(OffsetResetStrategy.LATEST); // first access, `id` member is populated with `toLowerCase` result System.out.println(OffsetResetStrategy.LATEST); // just uses `id` System.out.println(OffsetResetStrategy.LATEST); // just uses `id` System.out.println(OffsetResetStrategy.LATEST); // just uses `id` ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org