https://kotlinlang.org logo
#announcements
Title
# announcements
c

Constantin Weisser

11/19/2019, 12:34 PM
Can an anonymous object ever be non-final on the jvm?
d

Dominaezzz

11/19/2019, 12:37 PM
Does it matter?
c

Constantin Weisser

11/19/2019, 12:41 PM
I wanted to use it in a test ... I implemented an interface like
object : TheInterface { ... }
. But for mockito it needs to be non-final, so I have to write a whole class in the code. It’s not horrible but could be neater 🙂
d

Dominaezzz

11/19/2019, 12:43 PM
I guess you could try marking it as
open
but idk if that'll work.
c

Constantin Weisser

11/19/2019, 12:44 PM
It’s a syntax error 😄
d

diesieben07

11/19/2019, 12:45 PM
You could maybe work around it using the
allopen
compiler plugin with custom annotation. But I am not sure if it works on anonymous objects
k

kevinherron

11/19/2019, 12:47 PM
didn’t Mockito 2 lift this restriction via the MockMaker plugin?
or is this a special case?
t

tseisel

11/19/2019, 12:59 PM
Do you mean that you want to mock an anonymous class ? I'm curious about the use case. Why not mock the interface itself ?
c

Constantin Weisser

11/19/2019, 1:12 PM
I wanted to spy rather than mock actually ...
c

christophsturm

11/19/2019, 2:12 PM
I’m pretty sure that it works if you enable the mockmaker plugin
c

Constantin Weisser

11/20/2019, 10:14 AM
Will check that out, thanks