I am learning Scala and I am unable to figure out how to properly use commands from Java libraries in Scala. I show below what am trying to do in a command-line.
collier@Nacho-Laptop:~$ scala
Welcome to Scala version 2.9.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import java.text._
import java.text._ ^
scala> println(java.text.DateFormat.getCalendar())
<console>:11: error: value getCalendar is not a member of object java.text.DateFormat
println(java.text.DateFormat.getCalendar())
^
scala> println(java.text.getCalendar())
<console>:11: error: object getCalendar is not a member of package java.text
println(java.text.getCalendar())
^
scala> println(getCalendar())
<console>:11: error: not found: value getCalendar
println(getCalendar())
^
scala> getCalendar()
<console>:11: error: not found: value getCalendar
getCalendar()
^
scala>
The REPL error messages clearly show that getCalendar
is not defined for the DateFormat
class. You can simply call Calendar#getInstance()
scala> import java.util.Calendar
import java.util.Calendar
scala> println(Calendar.getInstance().getTime())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With