Using varargs from Scala

后端 未结 2 1462
走了就别回头了
走了就别回头了 2020-12-01 04:21

I\'m tearing my hair out trying to figure out how to do the following:

def foo(msf: String, o: Any, os: Any*) = {
    println( String.format(msf, o :: List(os         


        
相关标签:
2条回答
  • 2020-12-01 04:47
    def foo(msf: String, o: AnyRef, os: AnyRef*) =
      println( String.format(msf, o :: os.toList : _* ) )
    

    or

    def foo(msf: String, o: AnyRef, os: AnyRef*) =
          println( msf format (o :: os.toList : _* ) )
    

    I much prefer the latter, though it has no locale* support.

    • Scala 2.8 does have locale support with RichString's format.
    0 讨论(0)
  • 2020-12-01 04:50
    def foo(msf: String, o: AnyRef, os: AnyRef*) = 
      println( String.format(msf, (o :: os.toList).toArray : _* ))
    
    0 讨论(0)
提交回复
热议问题