# Primitive vararg failed to override generic vararg

**URL:** <https://discuss.kotlinlang.org/t/primitive-vararg-failed-to-override-generic-vararg/4453>\
**Category:** Language Design\
**Created:** [September 4, 2017, 7:13am UTC](https://discuss.kotlinlang.org/t/primitive-vararg-failed-to-override-generic-vararg/4453 "2017-09-04T07:13:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wumo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wumo/32/3831_2.png) [@wumo](https://discuss.kotlinlang.org/u/wumo)\
**Post date:** [September 4, 2017, 7:13am UTC](https://discuss.kotlinlang.org/t/primitive-vararg-failed-to-override-generic-vararg/4453/1 "2017-09-04T07:13:15Z")

</div>

The following code doesn’t compile and throw  
`Error Kotlin: Class 'Impl' is not abstract and does not implement abstract member public abstract fun process(vararg index: Int): Unit defined in Processor`.

```auto
interface Processor<T> {
    fun process(vararg index: T): Unit
}

class Impl : Processor<Int>{
    override fun process(vararg index: Int) {
        TODO("not implemented")
    }
}

```

But the following code compiles.

```auto
interface Processor<T> {
    fun process(vararg index: T): Unit
}

class Impl : Processor<Number>{
    override fun process(vararg index: Number) {
        TODO("not implemented")
    }
}

```

Why and how to deal with it?

---

<div class="post-metadata">

**Author:** ![wumo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wumo/32/3831_2.png) [@wumo](https://discuss.kotlinlang.org/u/wumo)\
**Post date:** [September 4, 2017, 7:30am UTC](https://discuss.kotlinlang.org/t/primitive-vararg-failed-to-override-generic-vararg/4453/2 "2017-09-04T07:30:48Z")

</div>

Using Kotlin Bytecode, `Processor`’s `process` funciton becomes `Object...var1` while `Impl` becomes `int...var1`.  
I know this is the cause. The question is how to avoid this? (In Java we can use Integer, In kotlin, we can only use Int.)

---

<div class="post-metadata">

**Author:** ![wumo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wumo/32/3831_2.png) [@wumo](https://discuss.kotlinlang.org/u/wumo)\
**Post date:** [September 4, 2017, 7:52am UTC](https://discuss.kotlinlang.org/t/primitive-vararg-failed-to-override-generic-vararg/4453/3 "2017-09-04T07:52:39Z")

</div>

according to [Force / hint of Int to java.lang.Integer?](https://discuss.kotlinlang.org/t/force-hint-of-int-to-java-lang-integer/2441), maybe we can use java.lang.Integer to solve this problem.  
But this will result in other problems about Integer and Int.  
In my example, the usage of `Processor` will be like `process(Integer(1),Integer(2))` instead of `process(1,1)`.

---

<div class="post-metadata">

**Author:** ![wumo](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wumo/32/3831_2.png) [@wumo](https://discuss.kotlinlang.org/u/wumo)\
**Post date:** [September 4, 2017, 8:17am UTC](https://discuss.kotlinlang.org/t/primitive-vararg-failed-to-override-generic-vararg/4453/4 "2017-09-04T08:17:48Z")

</div>

Another solution maybe using `Int?` to force boxed Int? This way will introduce null safety things.

---

<div class="post-metadata">

**Author:** ![vbezhenar](https://avatars.discourse-cdn.com/v4/letter/v/35a633/32.png) [@vbezhenar](https://discuss.kotlinlang.org/u/vbezhenar)\
**Post date:** [September 4, 2017, 8:53am UTC](https://discuss.kotlinlang.org/t/primitive-vararg-failed-to-override-generic-vararg/4453/5 "2017-09-04T08:53:50Z")

</div>

This looks like compiler bug. Compiler should use `java.lang.Integer` in this case. Using `Int?` looks like the best workaround.

---

<div class="post-metadata">

**Author:** ![alanfo](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@alanfo](https://discuss.kotlinlang.org/u/alanfo)\
**Post date:** [September 4, 2017, 8:57am UTC](https://discuss.kotlinlang.org/t/primitive-vararg-failed-to-override-generic-vararg/4453/6 "2017-09-04T08:57:43Z")

</div>

I don’t know whether this a compiler bug or just an inevitable consequence of the type system but I agree with @vbezhenar that the best solution is to use Int? rather than Int.

The null-checking aspects will be confined to your override of the process method as the method is not returning anything. Also you’ll be able to pass integer arguments ‘naturally’ instead of wrapping them in Integer objects.

Another problem with Integer is that the compiler doesn’t like you using it and will issue warnings if you do.
