diff --git a/docs/java.md b/docs/java.md
index da8b7ee7b0..7686d45e87 100644
--- a/docs/java.md
+++ b/docs/java.md
@@ -3666,6 +3666,7 @@ public java.lang.Object produce()
| **Name** | **Description** |
| --- | --- |
| any
| *No description.* |
+| isLazy
| Checks if an object is a Lazy instance. |
---
@@ -3683,6 +3684,24 @@ Lazy.any(IAnyProducer producer)
---
+##### `isLazy`
+
+```java
+import org.cdk8s.Lazy;
+
+Lazy.isLazy(java.lang.Object obj)
+```
+
+Checks if an object is a Lazy instance.
+
+###### `obj`Required
+
+- *Type:* java.lang.Object
+
+The object to check.
+
+---
+
### LazyResolver
diff --git a/docs/python.md b/docs/python.md
index ab3c0f219b..248735842b 100644
--- a/docs/python.md
+++ b/docs/python.md
@@ -3881,6 +3881,7 @@ def produce() -> typing.Any
| **Name** | **Description** |
| --- | --- |
| any
| *No description.* |
+| is_lazy
| Checks if an object is a Lazy instance. |
---
@@ -3900,6 +3901,26 @@ cdk8s.Lazy.any(
---
+##### `is_lazy`
+
+```python
+import cdk8s
+
+cdk8s.Lazy.is_lazy(
+ obj: typing.Any
+)
+```
+
+Checks if an object is a Lazy instance.
+
+###### `obj`Required
+
+- *Type:* typing.Any
+
+The object to check.
+
+---
+
### LazyResolver
diff --git a/docs/typescript.md b/docs/typescript.md
index 3c434b2f5a..4a61f72122 100644
--- a/docs/typescript.md
+++ b/docs/typescript.md
@@ -3183,6 +3183,7 @@ public produce(): any
| **Name** | **Description** |
| --- | --- |
| any
| *No description.* |
+| isLazy
| Checks if an object is a Lazy instance. |
---
@@ -3200,6 +3201,24 @@ Lazy.any(producer: IAnyProducer)
---
+##### `isLazy`
+
+```typescript
+import { Lazy } from 'cdk8s'
+
+Lazy.isLazy(obj: any)
+```
+
+Checks if an object is a Lazy instance.
+
+###### `obj`Required
+
+- *Type:* any
+
+The object to check.
+
+---
+
### LazyResolver
diff --git a/src/lazy.ts b/src/lazy.ts
index 8dc0f35b9e..696b34dca8 100644
--- a/src/lazy.ts
+++ b/src/lazy.ts
@@ -1,9 +1,31 @@
+const LAZY_SYMBOL = Symbol.for("cdk8s.Lazy");
+
export class Lazy {
public static any(producer: IAnyProducer): any {
return new Lazy(producer) as unknown as any;
}
- private constructor(private readonly producer: IAnyProducer) {}
+ /**
+ * Checks if an object is a Lazy instance
+ * @param obj The object to check
+ */
+ static isLazy(obj: any): boolean {
+ return obj !== null && typeof obj === "object" && LAZY_SYMBOL in obj;
+ }
+
+ /**
+ * Implements `instanceof Lazy` using the more reliable `Lazy.isLazy` static method
+ *
+ * @param obj The object to check
+ * @internal
+ */
+ public static [Symbol.hasInstance](obj: any): boolean {
+ return Lazy.isLazy(obj);
+ }
+
+ private constructor(private readonly producer: IAnyProducer) {
+ Object.defineProperty(this, LAZY_SYMBOL, { value: true });
+ }
public produce(): any {
return this.producer.produce();
@@ -13,5 +35,3 @@ export class Lazy {
export interface IAnyProducer {
produce(): any;
}
-
-