Guess it would be easier to just make it open and ...
# spring
a
Guess it would be easier to just make it open and make the setter private...
j
Why not simply val myField so you have public access without setter?
a
One issue is I am using it for calculations in the init block which idea hints at the need for it to be final (private)
only reason I'm really looking at a getter is so that I can test whether it is injected or not.
Maybe I should just scratch that test 🙂
j
I don't understand why it should be private or why such warning appears if you use it in init block
can you provide example code?
a
Copy code
@Service
class Demo(@Value("\${a.b}") private val a: String) {

private val b: String

init {
  b = someCalculation(a)
}
Conceptually something like this. In my case
a
is a cryptographic key, so ideally I don't even want the getter to exist for testing.
j
I don't get any warning if I remove private for val a in constructor
ah, now I found it
yeah I'm assuming you using kotlin-allopen plugin so class Demo is actually open class Demo, making it final class Demo makes warning disappear (but may break Spring stuff of course)
a
Yes, that's what I suspected too