Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want to define a default value for a variable argument parameter in a Scala method. Is it possible?
def aMethod(variableArguments: String* = ???){}
I have tried using variableArguments:String* = Seq("a","b","c"):_* but it doesn't work.
variableArguments:String* = Seq("a","b","c"):_*
The compiler error makes it pretty clear-cut:
:10: error: a parameter section with a `*'-parameter is not allowed to have default arguments
You can work around this with overloading, if you wish:
def test(a: String*): String = a.mkString def test(): String = test("a", "b", "c")
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.