Using varargs from Scala

后端 未结 2 1479
走了就别回头了
走了就别回头了 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.

提交回复
热议问题