Todd O'Bryan
Todd O'Bryan

Reputation: 2260

How do I tell Scala to use the right Java constructor?

I'm trying to use JodaTime in Scala. So I did

import org.joda.time.DateTime

val dt = new DateTime(2011, 10, 8, 18, 30) // try to set to 6:30 pm, Oct 8, 2011

Unfortunately, Scala thinks I'm trying to use the DateTime(Object) constructor instead of the 5 int constructor, and, not surprisingly, a Tuple5 is not the kind of Object JodaTime was expecting.

How do I tell Scala to use the 5-int constructor?

Todd

Upvotes: 2

Views: 240

Answers (1)

leedm777
leedm777

Reputation: 24072

It's probable that you're using an older version of JodaTime. The constructor you are trying to use didn't exist until JodaTime 2.0.

Older versions of JodaTime had no 5 param ctor. Since Scala can't find one, it assumes that you're attempting to pass in a tuple, which matches the Object ctor. You can find more details in this excellent answer.

Upvotes: 8

Related Questions