Is this function “returning an object of type Disp...
# getting-started
s
Is this function “returning an object of type Dispatcher, but since Dispatcher is an abstract class I have to use the object keyword and declare that object as an instance of the abstract class?” 😐 not sure about this part:
: Dispatcher = object : Dispatcher()
Copy code
fun updateErrorCodeForUrl(url: String, errorCode: Int) : Dispatcher = object : Dispatcher() {
        @Throws(InterruptedException::class)
        override fun dispatch(request: RecordedRequest): MockResponse {
            when (request.path) {
                url -> return MockResponse()
                    .setResponseCode(errorCode)
            }
            return MockResponse().setResponseCode(422)
        }
    }
s
uh, part of what might be confusing you is the expression body syntax
the block body version would look like this
Copy code
fun updateErrorCodeForUrl(url: String, errorCode: Int): Dispatcher {
   return object : Dispatcher() {
d
the answer to your question is yes, though
s
object : SuperType
is how anonymous classes are instantiated with an inheriting class or interface
s
Thanks 😃