Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String.format causes an error

Tags:

scala

Scala code I have

System.out.println(String.format("%s %6d", "someName", someLong))

and the error:

 overloaded method value format with alternatives:
[error]   (java.util.Locale,java.lang.String,<repeated...>[java.lang.Object])java.lang.String <and>
[error]   (java.lang.String,<repeated...>[java.lang.Object])java.lang.String
[error]  cannot be applied to (java.lang.String, Long, String)
[error]       System.out.println(String.format("%s %6d",  "someName", someLong))

How do I solve this?

like image 943
Alan Coromano Avatar asked Feb 16 '23 01:02

Alan Coromano


1 Answers

To illustrate Randall's answer.

If you're over fifty, use Randall's answer, but if you're under forty or can still wear fitted shirts, use the f-interpolator! Life is short.

scala> String.format("%s %6d", "someName", someLong: java.lang.Long)
res8: String = someName      5

scala> val someName = "Bob"
someName: String = Bob

scala> f"${someName} ${someLong}%6d"
res10: String = Bob      5
like image 124
som-snytt Avatar answered Feb 27 '23 13:02

som-snytt