Member-only story
Java Enum — Interesting Insight
Happened to write some code earlier today using enums in Java. I came across a very trivial yet interesting catch. Eventually, led to me exploring more about global singletons, immutable classes and enums as a whole. Read through to understand more about the issue I faced and how I resolved it.
While the resolution is straightforward and easy to figure, the problem was intriguing and interesting to know about.
package org.example;
import lombok.*;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
List<Tabs> tabs = new ArrayList<>();
Tabs tab1 = Tabs.builder().searchKey("ratings").operator("GE").searchValue(List.of("4.8")).build();
Tabs tab2 = Tabs.builder().searchKey("Brand").operator("IN").searchValue(List.of("CRAFTSMAN")).build();
tabs.add(tab1);
tabs.add(tab2);
FilterConfigs filterConfigs = FilterConfigs.builder().ratings(null).reviews(null).tabsList(tabs).build();
List<Request> requestList = new ArrayList<>();
filterConfigs.tabsList.forEach(config -> {
Filters customFilterKey = Filters.CUSTOM;
customFilterKey.setCustomValue(config.getSearchKey());
Request requestFilter = Request.builder().filter(customFilterKey)…








