Home > Software engineering >  'Expecting a top level declaration' when creating a Kotlin Class
'Expecting a top level declaration' when creating a Kotlin Class

Time:11-13

I am getting this error Expecting a top level declaration on this very simple class declaration

public class NetworkConnectionInterceptor implements Interceptor{

}

I have done invalidate cache several times but the error still exists, any ideas please?

enter image description here

CodePudding user response:

Pay attention to the file type, its .kt, meaning its Kotlin.

What your'e attempting here is Java

public class NetworkConnectionInterceptor implements Interceptor{

}

So please do it this way if you want a Kotlin class,

class NetworkConnectionInterceptor : Interceptor {

}

But if you really want this as Java, you then have to create a new file as Java

  • Related