-3

Okay I have an interface which has few interfaces in it and the code looks like this in Kotlin

interface IStreamRepository : IBaseRepository {

interface OnAddStreamCallback {
    fun onSuccess()
    fun onError(message: String)
}

interface OnGetAllStreamsCallback {
    fun onSuccess(streams: ArrayList<Stream>)
    fun onError(message: String)
}

interface OnGetStreamByNameCallback {
    fun onSuccess(stream: Stream)
    fun onError(message: String)
}

interface OnDeleteStreamCallback {
    fun onSuccess()
    fun onError(message: String)
}
}

and when I try to do

getAllStreamsCallBack = IStreamRepository.OnGetAllStreamsCallback() {
    //and override methods in OnGetAllStreamsCallback interface 
}

the compiler throws the following error OnGetAllStreamsCallback does not have constructors, How can I solve this issue?

s1m0nw1
  • 76,759
  • 17
  • 167
  • 196
vinay kumar
  • 555
  • 1
  • 6
  • 16
  • 1
    That question concerns annotations ([`@interface`](https://stackoverflow.com/questions/918393/whats-the-difference-between-interface-and-interface-in-java)) – Salem Dec 21 '17 at 19:30
  • 1
    Please next time ensure that problem really exists before posting a question. – user882813 Dec 21 '17 at 19:49

2 Answers2

5

The linked question is related to nested annotation classes. You can nest interfaces without problems:

interface Outer {
    interface Inner
}

fun main(args: Array<String>) {
    val o = object : Outer {}
    val i = object : Outer.Inner {}
}
s1m0nw1
  • 76,759
  • 17
  • 167
  • 196
2

when I try to do getAllStreamsCallBack = IStreamRepository.OnGetAllStreamsCallback() { and override methods in OnGetAllStreamsCallback interface } the compiler throws the following error OnGetAllStreamsCallback dose not have constructors

You'd get the same error with a non-nested interface. The syntax is getAllStreamsCallBack = object : IStreamRepository.OnGetAllStreamsCallback { ... }. If it was a class, you'd need () after the name, for an interface you don't.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487