fabricio
06/21/2018, 4:17 PMfun findProfile(user: UserDocument, vararg fields: String) { ... }
I'd like to make the vararg parameter required, because if I call that method like userService.findProfile(user)
it doesn't complain.
Any idea?Czar
06/21/2018, 4:26 PM0
, so no, you can't make it work like you want, except checking args length and throwing an IllegalArgumentException
.
What you can do (I know it's not very beautiful) is:
fun findProfile(user: UserDocument, firstField: String, vararg additionalFields: String) { ... }
This will force your users to supply at least one field. And will look similar to what you want at the call site.