{"id":5600,"date":"2018-01-03T03:08:08","date_gmt":"2018-01-03T03:08:08","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=5600"},"modified":"2018-01-03T03:08:08","modified_gmt":"2018-01-03T03:08:08","slug":"fixing-scala-error-string-format-overloaded-method-value-format-alternatives","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/fixing-scala-error-string-format-overloaded-method-value-format-alternatives\/","title":{"rendered":"Fixing Scala error on String.format: overloaded method value format with alternatives:"},"content":{"rendered":"<p>If you try to use a &#8220;Double&#8221; in scala, you may get errors passing it to Java:<\/p>\n<pre lang=\"scala\">\nString.format(\"%-30s: %.2f \u00b1 %0.2f\", kv._1, kv._2, kv._3)\n<\/pre>\n<p>This is the error I got:<\/p>\n<pre lang=\"scala\">\n[error] D:\\projects\\scala-indexer\\src\\main\\scala\\indexer\\GpuConcepts.scala:114: overloaded method value format with alternatives:\n[error]   (x$1: java.util.Locale,x$2: String,x$3: Object*)String <and>\n[error]   (x$1: String,x$2: Object*)String\n[error]  cannot be applied to (String, String, Double, Double)\n[error]             String.format(\"%-30s: %.2f \u2592 %0.2f\", kv._1, kv._2, kv._3)\n<\/pre>\n<p>The issue here is that &#8220;Double&#8221;, as in &#8220;scala.Double&#8221; is the equivalent of the primitive &#8220;double&#8221; in Java. You can fix it by boxing the value:<\/p>\n<pre lang=\"scala\">\nString.format(\"%-30s: %.2f \u00b1 %0.2f\", kv._1, Double.box(kv._2), Double.box(kv._3))\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Errors with string.format in scala<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[9],"tags":[480],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5600"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=5600"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5600\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=5600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=5600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=5600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}