summaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-06-13 22:13:00 -0700
committerGitHub <noreply@github.com>2025-06-13 22:13:00 -0700
commit6a23949f07f4eba38086b656e7073ce3bf8cd2fe (patch)
tree132bbe330b6027d323c74175686d006605e4da6d /docs
parente72b3325663ab6d4bb791742574b031f0df6328a (diff)
Allow interface methods to have default implementations. (#7439)
Diffstat (limited to 'docs')
-rw-r--r--docs/user-guide/06-interfaces-generics.md13
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/user-guide/06-interfaces-generics.md b/docs/user-guide/06-interfaces-generics.md
index b90bc04ba..1912fcb02 100644
--- a/docs/user-guide/06-interfaces-generics.md
+++ b/docs/user-guide/06-interfaces-generics.md
@@ -43,8 +43,21 @@ struct MyType : IFoo, IBar
uint myMethod2(uint2 x) {...}
}
```
+
In this case, the definition of `MyType` must satisfy the requirements from both the `IFoo` and `IBar` interfaces by providing both the `myMethod` and `myMethod2` methods.
+Interface methods can have a default implementation, which will be used if a conforming type doesn't provide an overriding implementation. For example:
+
+```slang
+interface IFoo
+{
+ int getVal() { return 0; }
+}
+
+// OK, MyType.getVal() will use the default implementation provided in `IFoo`.
+struct MyType : IFoo {}
+```
+
Generics
---------------------