# Weird error “incompatible types: Set\<CAP#1\> cannot be converted to Set\<Integer\>” when calling Kotlin from Java

**URL:** <https://discuss.kotlinlang.org/t/weird-error-incompatible-types-set-cap-1-cannot-be-converted-to-set-integer-when-calling-kotlin-from-java/19633>\
**Category:** Uncategorized\
**Created:** [October 24, 2020, 1:52pm UTC](https://discuss.kotlinlang.org/t/weird-error-incompatible-types-set-cap-1-cannot-be-converted-to-set-integer-when-calling-kotlin-from-java/19633 "2020-10-24T13:52:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oakkitten](https://avatars.discourse-cdn.com/v4/letter/o/7cd45c/32.png) [@oakkitten](https://discuss.kotlinlang.org/u/oakkitten)\
**Post date:** [October 24, 2020, 1:52pm UTC](https://discuss.kotlinlang.org/t/weird-error-incompatible-types-set-cap-1-cannot-be-converted-to-set-integer-when-calling-kotlin-from-java/19633/1 "2020-10-24T13:52:44Z")

</div>

I have this code which I was able to reduce to the following:

```kotlin
open class Base<T>(val t: T)

class Moo<E>(val e: Set<E>) : Base<Set<E>>(e)

val moo = Moo(setOf(1))

val z: Set<Int> = moo.t // ok

```

So far so good, but I wanted to do that last line in Java:

```java
Set<Integer> z = getMoo().getT();

// error: incompatible types: Set<CAP#1> cannot be converted to Set<Integer>
// where CAP#1 is a fresh type-variable:
// CAP#1 extends Integer from capture of ? extends Integer

```

But I’m not doing any wildcards am I? Isn’t `E` invariant? What’s going on?

Funnily, there error disappears if I define `Moo` as

```kotlin
class Moo<E, S : Set<E>>(val e: S) : Base<S>(e)

```

---

<div class="post-metadata">

**Author:** ![Varia](https://avatars.discourse-cdn.com/v4/letter/v/b9e5f3/32.png) [@Varia](https://discuss.kotlinlang.org/u/Varia)\
**Post date:** [October 24, 2020, 4:06pm UTC](https://discuss.kotlinlang.org/t/weird-error-incompatible-types-set-cap-1-cannot-be-converted-to-set-integer-when-calling-kotlin-from-java/19633/2 "2020-10-24T16:06:19Z")

</div>

In Kotlin, the interface `Set` is declared as `interface Set<out E>`. This means that whenever you write `Set<SomeType>` it is compiled to `Set<? extends SomeType>`. This is described in further detail [here](https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html#variant-generics)
