Vararg function parameter with default value?


#1

Is there a way to specify a default value for a vararg type parameter of a function?
So basically, I would like to do this:

fun AppCompatActivity.startActivityForResultWithTransition(intent: Intent, requestCode: Int, vararg sharedViews: View? = null)

In order, to call it from my activity like:

 startActivityWithTransition(FundingSummaryActivity.getStartIntent(this), binding.onboardingToolbar, binding.onboardingProgress, binding.readyToStart);

#2

i am sorry i don’t understand.

Vararg parameter is optional, why you should define a default value for an optional parameter?

You can simply omit it.


#3

vararg by definition already has a default, which is an empty array.