سؤال

Why does not this work? In a Java code:

import scala.collections.immutable.Range;

// ...

Range r = Range.apply(0, 10)

Eclipse says:

The method apply(int) in the type Range is not applicable for the arguments (int, int)

And SBT says:

error: method apply in class Range cannot be applied to given types;

However, there is an apply(Int, Int) method in the collections.immutable.Range object of the Scala API.

هل كانت مفيدة؟

المحلول

That's because you're calling the apply(int) method from the Range class. You should be calling apply(int,int) from the companion object:

import scala.collection.immutable.Range$;
// ...
Range r = Range$.MODULE$.apply(0, 10)

See also this Q&A for general info.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top