From eb0c75b601de6b4323bb40ae34cde1df8e2468ee Mon Sep 17 00:00:00 2001 From: Jose Carranza Date: Wed, 15 Nov 2023 15:54:49 +0100 Subject: [PATCH] convert shoppingList as static field and improve the get method to avoid lazily initialization --- .../io/quarkus/ts/vertx/web/validation/ShopResource.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ShopResource.java b/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ShopResource.java index d02040b597..73ee3bca3f 100644 --- a/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ShopResource.java +++ b/http/vertx-web-validation/src/main/java/io/quarkus/ts/vertx/web/validation/ShopResource.java @@ -14,9 +14,9 @@ @Produces(MediaType.APPLICATION_JSON) public class ShopResource { - private List shoppingList; + private static List shoppingList = createSampleProductList(); - private List createSampleProductList() { + private static List createSampleProductList() { shoppingList = new ArrayList<>(); shoppingList.add(new ShoppingList(UUID.randomUUID(), "ListName1", 25, new ArrayList<>(Arrays.asList("Carrots", "Water", "Cheese", "Beer")))); @@ -27,9 +27,6 @@ private List createSampleProductList() { @GET public List get() { - if (shoppingList == null) { - createSampleProductList(); - } return shoppingList; }