WelcomeTo
WelcomeTo

Reputation: 20571

Error when calling apply method on BigInt

Why I get error (value apply is not a member of scala.math.BigInt) when I try to execute following code?

var a : BigInt = 12;
a.apply("123", 36);

BigInt#apply is defined in ScalaDoc. Also I tried using implicit apply method invocation, it also doesn't work:

a("123", 36);

(And second question: It's true for all objects that calling () is equal to calling object.apply or object apply ?)

Upvotes: 0

Views: 236

Answers (2)

nilskp
nilskp

Reputation: 3127

BigInt#apply refers to the object BigInt, not the class BigInt. Specifically to call this method do the following:

BigInt.apply("123", 36)

Or, because apply is the special method which looks like function application:

BigInt("123", 36)

Upvotes: 6

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340693

apply() is a method of BigInt companion object, not BigInt class itself. Thus you can say:

val a = BigInt("123", 36)

Moreover, what do you expect from a("123", 36)? BigInt is immutable.

Upvotes: 3

Related Questions