gpt4 book ai didi

java - 范围类 : java interoperability

转载 作者:行者123 更新时间:2023-12-01 23:09:06 25 4
gpt4 key购买 nike

为什么这不起作用?在 Java 代码中:

import scala.collections.immutable.Range;

// ...

Range r = Range.apply(0, 10)

Eclipse 说:

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

SBT 说:

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

但是,Scala API 的 collections.immutable.Range 对象中有一个 apply(Int, Int) 方法。

最佳答案

那是因为您正在调用 apply(int)方法来自 Range class 。您应该调用apply(int,int)来自the companion object :

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

另请参阅this Q&A了解一般信息。

关于java - 范围类 : java interoperability,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22288813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com