This page is no longer maintained — Please continue to the home page at www.scala-lang.org

How to invoke the Java's static method?

3 replies
Guofeng Zhang
Joined: 2010-08-17,
User offline. Last seen 42 years 45 weeks ago.

Hi,

In Scala, I want to invoke a static method of a Java class, like the
parse() in org.joda.time.DateTime:
val t = DateTime.parse( value )
But the compile complaint that "error: value parse is not a member of
object org.joda.time.DateTime".

How to solve it?

In my other code, calling the static method of a Java class passes the
compilation, but sometime like the above does not. I do not know why.

Guofeng

Thanks

nilskp
Joined: 2009-01-30,
User offline. Last seen 1 year 27 weeks ago.
Re: How to invoke the Java's static method?
I bet you're missing the joda-convert dependency, which the compiler unfortunately, in many cases, is not nice enough to ask for.

On Sat, Feb 11, 2012 at 12:40 PM, Guofeng Zhang <guofeng@radvision.com> wrote:
Hi,

In Scala, I want to invoke a static method of a Java class, like the
parse() in org.joda.time.DateTime:
       val t = DateTime.parse( value )
But the compile complaint that "error: value parse is not a member of
object org.joda.time.DateTime".

How to solve it?

In my other code, calling the static method of a Java class passes the
compilation, but sometime like the above does not. I do not know why.

Guofeng

Thanks

vpatryshev
Joined: 2009-02-16,
User offline. Last seen 1 year 24 weeks ago.
Re: How to invoke the Java's static method?
Here this issue is discussed in kind of details:

http://stackoverflow.com/questions/4445617/calling-a-protected-static-java-method-from-scala

Thanks,
-Vlad


On Sat, Feb 11, 2012 at 9:40 AM, Guofeng Zhang <guofeng@radvision.com> wrote:
Hi,

In Scala, I want to invoke a static method of a Java class, like the
parse() in org.joda.time.DateTime:
       val t = DateTime.parse( value )
But the compile complaint that "error: value parse is not a member of
object org.joda.time.DateTime".

How to solve it?

In my other code, calling the static method of a Java class passes the
compilation, but sometime like the above does not. I do not know why.

Guofeng

Thanks

Guofeng Zhang
Joined: 2010-08-17,
User offline. Last seen 42 years 45 weeks ago.
Re: How to invoke the Java's static method?

Nils,

You are right. I only node the tip on IDE, not pay attention to the
message displayed on the Problem panel. The message in that panel has
the following message:
[ERROR] error: error while loading DateTime, Missing dependency 'class
org.joda.convert.FromString', required by C:\.m2\repository\joda-time
\joda-time\2.0\joda-time-2.0.jar(org/joda/time/DateTime.class)

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland