'final' is deprecated inside 'interface' but my code is not compiled without 'final'


#1

 

package interfaceinline

import java.util.ArrayList

interface ListHasShape<H: HasShape>:Iterable<H>{
  val list: ArrayList<H>

  inline final fun <reified T : Data> by() = emptyList<T>()
}

open class HasShape(var shape: Shape)

interface Data

abstract class Shape


If I preserve ‘final’ then

Modifier ‘final’ is deprecated inside 'interface’


If I remove ‘final’ then

 ‘‘inline’’ modifier is not allowed on virtual members. Only private or final members can be inlined.


How to write properly?

PS. Full project code is here.


#2

In your case the solution would be to move the function out of the interface and make it an extension:

interface ListHasShape<H: HasShape>:Iterable<H>{
    val list: ArrayList<H>
}
inline fun <reified T : Data> ListHasShape<*>.by() = emptyList<T>()