Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Java locale in Scala complains: object is not a value

Tags:

java

scala

locale

I'm trying to use a java locale in Scala. Using a constant like java.util.Locale.ENGLISH works well; however, java.util.Locale("en") complains:

error: object Locale is not a value
java.util.Locale("en")`

This seems related to this question, which suggests Locale doesn't have a companion object. I've been reading a bit about this, but I still can't figure out how one is to access the Locale class?

like image 980
scala_newbie Avatar asked Jan 15 '23 22:01

scala_newbie


1 Answers

Do not forget to instantiate locale with new keyword, since it's class:

scala> new java.util.Locale("en")
res0: java.util.Locale = en
like image 140
om-nom-nom Avatar answered Jan 17 '23 10:01

om-nom-nom