I end up writing a lot of ```@Bean fun springClass...
# spring
h
I end up writing a lot of
Copy code
@Bean
fun springClassInstance() = SpringClass().apply {
    setA(a)
    setB(b)
    setC(c)
}
this syntax just makes me cry. it's a shame there can't be more constructor variants or at the very least builders for some of these classes... it would be so much nicer to just be
Copy code
@Bean fun springClassInstance() = SpringClass(a = a, b = b, c = c)
but you know.... java things. nvm me, complaining to the ether
Technically the yearned-for syntax is achievable in a marginally hacky way:
Copy code
object SpringClass {
    operator fun invoke(a: A, b: B, c: C) = SpringClass().apply {
        setA(a)
        setB(b)
        setC(c)
    }
}
but the confusion of importing this object instead of the actual class sacrifices all the readability that such syntax would offer, i think
t
Copy code
@Bean
fun springClassInstance() = SpringClass().apply {
    a = a
    b = b
    c = c
}
This notation is very simmilar to the one with constructor
h
often spring classes are interface implementations that don't have backing fields, so
a = a
does not compile and you have to use
setA(a)
m
you don't need backing field for property access to work
whenever you have
void setA(A a)
method in java, you should be able to call if with
obj.a = someA
h
image.png
@Marko Mitic So yeah, my complaint stands in this case