From 45bbd65ae28ae2799031a7c3f4f19187ca95ed0c Mon Sep 17 00:00:00 2001 From: Leo Galambos Date: Sun, 6 Jul 2025 18:24:12 +0200 Subject: [PATCH] Update Programming Guide --- Programming-Guide.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Programming-Guide.md b/Programming-Guide.md index 266930f..1472015 100644 --- a/Programming-Guide.md +++ b/Programming-Guide.md @@ -17,10 +17,10 @@ import conflux.Listener; Define typed keys for the data you want to store: ```java -Key counterKey = new Key<>("counter", Integer.class); -Key nameKey = new Key<>("name", String.class); -Key arrayKey = new Key<>("numbers", int[].class); -Key pojoKey = new Key<>("myPojo", MyPojo.class); +Key counterKey = Key.of("counter", Integer.class); +Key nameKey = Key.of("name", String.class); +Key arrayKey = Key.of("numbers", int[].class); +Key pojoKey = Key.of("myPojo", MyPojo.class); ``` ## Storing and Retrieving Values @@ -121,11 +121,11 @@ Ctx.INSTANCE.put(pojoKey, new MyPojo("Widget Pro", 99)); // triggers listener Once a key is registered with a type, you cannot use the same name with a different type: ```java -Key myKey = new Key<>("sharedKey", Integer.class); +Key myKey = Key.of("sharedKey", Integer.class); Ctx.INSTANCE.put(myKey, 5); // later: -Key badKey = new Key<>("sharedKey", String.class); +Key badKey = Key.of("sharedKey", String.class); Ctx.INSTANCE.put(badKey, "wrong type"); // throws IllegalStateException ``` @@ -153,7 +153,7 @@ Ctx.INSTANCE.clear(); ## Complete Example ```java -Key temperatureKey = new Key<>("temperature", Integer.class); +Key temperatureKey = Key.of("temperature", Integer.class); Listener display = t -> System.out.println("Temperature changed to " + t + "°C");