Hello! Quick question for Kotlin users with Spring.. When you are using constructor injection with spring do you keep the constructor classes as nullable or not nullable?
for example;
Copy code
@Service
class FirestoreService(
private val firestore: Firestore?,
)
vs.
Copy code
@Service
class FirestoreService(
private val firestore: Firestore,
)
m
Mikhail
07/19/2022, 10:17 PM
Nullable type:
If you make an injected bean type nullable, then the injection will be considered as non-required, which is equal to:
Copy code
@Service
class FirestoreService(
@Autowired(required = false)
private val firestore: Firestore?,
)
Not nullable type:
Injection is required, Spring will throw an error if it cant satisfy a property
g
Gorkem Yurtseven
07/19/2022, 11:46 PM
alright this makes sense!
m
Mikhail
07/20/2022, 12:43 AM
Yeah, also note that Spring checks the property for the