How to: _ * convert ordered collections to arg variable lists?

I used :_* to convert Seq[String] to String* , and I realized that I did not understand how this works under the hood.

Is there an easy way to think about this?

+6
source share
1 answer

Under the hood, String* is passed as Seq[String] . This is just syntactic sugar:

 def blah(ss: String*) = {...} blah("Hi","there") 

turns into

 def blah(ss: Seq[String]) = {...} blah(Seq("Hi", "there")) 

and :_* just means "keep sugar, I already got what you need - Seq!"

+7
source

Source: https://habr.com/ru/post/909573/


All Articles