# Improve online Kotlin documentation for the \`where\` clause

**URL:** <https://discuss.kotlinlang.org/t/improve-online-kotlin-documentation-for-the-where-clause/11941>\
**Category:** Uncategorized\
**Created:** [March 12, 2019, 6:20pm UTC](https://discuss.kotlinlang.org/t/improve-online-kotlin-documentation-for-the-where-clause/11941 "2019-03-12T18:20:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TrombaMarina](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/trombamarina/32/2092_2.png) [@TrombaMarina](https://discuss.kotlinlang.org/u/TrombaMarina)\
**Post date:** [March 12, 2019, 6:20pm UTC](https://discuss.kotlinlang.org/t/improve-online-kotlin-documentation-for-the-where-clause/11941/1 "2019-03-12T18:20:10Z")

</div>

@gidds brought to my attention that [the `where` keyword makes an intersection type, not a union type](https://discuss.kotlinlang.org/t/why-kotlin-doesnt-allow-use-site-variance-with-the-interface/11912/4). I assumed the opposite. The docs should be more explicit.

Under the online documentation for [Generics: Constraints](https://kotlinlang.org/docs/reference/generics.html#generic-constraints), it says, “Only one upper bound can be specified inside the angle brackets. If the same type parameter needs more than one upper bound, we need a separate **where** -clause”

I recommend adding a little more, like, “A where clause creates an intersection type - each sub-clause must be satisfied. The type parameter specified this way must be a subtype of A and B and C etc.”

This little code snippet proves the above:

```kotlin
// Create some interfaces...
interface A {
    val foo: String
}
interface B {
    val bar: Int
}

// Type T must be both and A and a B
fun <T> baz(t: T): String where T : A, T : B {
    return t.foo + t.bar
}

// Now test baz()
fun fud(): String {

    // ERROR: Inferred type is not a subtype of B
// val t = object: A {
// override val foo: String = "hi"
// }

    // ERROR: Inferred type is not a subtype of A
// val t = object: B {
// override val bar: Int = 5
// }

    // Works - t must be a subtype of both A and B.
    val t = object: A, B {
        override val foo: String = "hi"
        override val bar: Int = 5
    }
    return baz(t) // returns "hi5"
}

```

---

<div class="post-metadata">

**Author:** ![AlexeySoshin](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alexeysoshin/32/5976_2.png) [@AlexeySoshin](https://discuss.kotlinlang.org/u/AlexeySoshin)\
**Post date:** [March 13, 2019, 8:53am UTC](https://discuss.kotlinlang.org/t/improve-online-kotlin-documentation-for-the-where-clause/11941/2 "2019-03-13T08:53:39Z")

</div>

Why not simply fork the documentation and submit a PR?  
[https://github.com/JetBrains/kotlin-web-site/edit/master/pages/docs/reference/generics.md](https://github.com/JetBrains/kotlin-web-site/edit/master/pages/docs/reference/generics.md)

---

<div class="post-metadata">

**Author:** ![TrombaMarina](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/trombamarina/32/2092_2.png) [@TrombaMarina](https://discuss.kotlinlang.org/u/TrombaMarina)\
**Post date:** [March 13, 2019, 2:29pm UTC](https://discuss.kotlinlang.org/t/improve-online-kotlin-documentation-for-the-where-clause/11941/3 "2019-03-13T14:29:57Z")

</div>

> [@TrombaMarina](#):
>
> A where clause creates an intersection type - each sub-clause must be satisfied.

[I did it](https://github.com/JetBrains/kotlin-web-site/pull/1329)! I read that you need a docker container to build the docs and imagined a long process. I was unsure if what I had to say was correct and worthy of being in the docs.

I never did the tiny fork/pull-request turnaround through the GitHub UI before. It was really easy! I guess I just needed a little encouragement. Thank you for that!

---

<div class="post-metadata">

**Author:** ![Pavel.Semyonov](https://avatars.discourse-cdn.com/v4/letter/p/65b543/32.png) [@Pavel.Semyonov](https://discuss.kotlinlang.org/u/Pavel.Semyonov)\
**Post date:** [March 14, 2019, 3:43am UTC](https://discuss.kotlinlang.org/t/improve-online-kotlin-documentation-for-the-where-clause/11941/4 "2019-03-14T03:43:23Z")

</div>

Hi!  
Thanks for the addition.  
I’ve suggested minor formatting and wording changes in the PR. We wrap names of functions and classes in backticks.
