Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java变量中的scala.Int,该变量存储scala函数中的值_Java_Scala - Fatal编程技术网

Java变量中的scala.Int,该变量存储scala函数中的值

Java变量中的scala.Int,该变量存储scala函数中的值,java,scala,Java,Scala,我有一个Scala集合历史,如下所示: import scala.collection.mutable.{Map => mm, Set => mSet} private var history: mm[Int, mSet[String]] = mm[Int, mSet[String]]() 和getHistory()Scala函数返回history以键入mm[Int,mSet[String]]。这是存储history返回值的Java代码 import scala.collectio

我有一个Scala集合
历史
,如下所示:

import scala.collection.mutable.{Map => mm, Set => mSet}
private var history: mm[Int, mSet[String]] = mm[Int, mSet[String]]()
getHistory()
Scala函数返回
history
以键入
mm[Int,mSet[String]]
。这是存储
history
返回值的Java代码

import scala.collection.mutable.Map;
import scala.collection.mutable.Set;
??? history = Database.getHistory();
问题是只有
Map
不会导致错误。我尝试了
Map
Map
,但没有任何效果

为什么会出现这种错误? 我需要将键作为一组整数(或迭代器)来获取,以便对它们进行迭代/排序


问题在于Java“foreach”循环的编码仅用于处理Java可重用类型,并且不能识别Scala集是它可以迭代的对象。您可以自己尝试一种旧式的循环调用
iterator
next
,等等,也可以先将集合转换为Java等价物(不过,在Scala代码中可能更容易实现)。

问题在于Java“foreach”循环的编码仅用于处理Java iterable类型,而且不认为Scala集是可以迭代的。您可以自己尝试一种旧式的循环调用
iterator
next
,等等,也可以先将集合转换为Java等价物(不过,在Scala代码中可能更容易实现)。

问题在于Java“foreach”循环的编码仅用于处理Java iterable类型,而且不认为Scala集是可以迭代的。您可以自己尝试一种旧式的循环调用
iterator
next
,等等,也可以先将集合转换为Java等价物(不过,在Scala代码中可能更容易实现)。

问题在于Java“foreach”循环的编码仅用于处理Java iterable类型,而且不认为Scala集是可以迭代的。您可以自己显式地尝试循环调用
iterator
next
等旧样式,或者先将集合转换为Java等价物(不过在Scala代码中可能更容易实现)。

JavaConversion
可以将keySet()转换为iterables

    Map<Object, Set<String>> history = Database.getHistory();

    Iterable<Object> keys = JavaConversions.asJavaIterable(history.keySet());

    for (Object key : keys) {
        int k = (int)key;
        System.out.printf("%d-%s\n", k, history.get(k).get().toString());
    }
Map history=Database.getHistory();
Iterable keys=JavaConversions.asJavaIterable(history.keySet());
用于(对象关键点:关键点){
int k=(int)键;
System.out.printf(“%d-%s\n”,k,history.get(k.get().toString());
}
对于Int问题,我可以在scala代码中将scala.Int更改为java.Integer,但对象似乎工作正常

对于排序键,根据来自的提示,我可以只填充键

    List<Integer> sortedList = new ArrayList<>();
    for (Object i : keys) {
        sortedList.add((int)i);
    }
    Collections.sort(sortedList);

    for (int key : sortedList) {
        System.out.printf("%d-%s\n", key, history.get(key).get().toString());
    }
List sortedList=new ArrayList();
用于(对象i:关键点){
分类列表。添加((int)i);
}
收集.分类(分类列表);
用于(int键:sortedList){
System.out.printf(“%d-%s\n”,键,history.get(键).get().toString());
}

JavaConversion
可以将keySet()转换为iterables

    Map<Object, Set<String>> history = Database.getHistory();

    Iterable<Object> keys = JavaConversions.asJavaIterable(history.keySet());

    for (Object key : keys) {
        int k = (int)key;
        System.out.printf("%d-%s\n", k, history.get(k).get().toString());
    }
Map history=Database.getHistory();
Iterable keys=JavaConversions.asJavaIterable(history.keySet());
用于(对象关键点:关键点){
int k=(int)键;
System.out.printf(“%d-%s\n”,k,history.get(k.get().toString());
}
对于Int问题,我可以在scala代码中将scala.Int更改为java.Integer,但对象似乎工作正常

对于排序键,根据来自的提示,我可以只填充键

    List<Integer> sortedList = new ArrayList<>();
    for (Object i : keys) {
        sortedList.add((int)i);
    }
    Collections.sort(sortedList);

    for (int key : sortedList) {
        System.out.printf("%d-%s\n", key, history.get(key).get().toString());
    }
List sortedList=new ArrayList();
用于(对象i:关键点){
分类列表。添加((int)i);
}
收集.分类(分类列表);
用于(int键:sortedList){
System.out.printf(“%d-%s\n”,键,history.get(键).get().toString());
}

JavaConversion
可以将keySet()转换为iterables

    Map<Object, Set<String>> history = Database.getHistory();

    Iterable<Object> keys = JavaConversions.asJavaIterable(history.keySet());

    for (Object key : keys) {
        int k = (int)key;
        System.out.printf("%d-%s\n", k, history.get(k).get().toString());
    }
Map history=Database.getHistory();
Iterable keys=JavaConversions.asJavaIterable(history.keySet());
用于(对象关键点:关键点){
int k=(int)键;
System.out.printf(“%d-%s\n”,k,history.get(k.get().toString());
}
对于Int问题,我可以在scala代码中将scala.Int更改为java.Integer,但对象似乎工作正常

对于排序键,根据来自的提示,我可以只填充键

    List<Integer> sortedList = new ArrayList<>();
    for (Object i : keys) {
        sortedList.add((int)i);
    }
    Collections.sort(sortedList);

    for (int key : sortedList) {
        System.out.printf("%d-%s\n", key, history.get(key).get().toString());
    }
List sortedList=new ArrayList();
用于(对象i:关键点){
分类列表。添加((int)i);
}
收集.分类(分类列表);
用于(int键:sortedList){
System.out.printf(“%d-%s\n”,键,history.get(键).get().toString());
}

JavaConversion
可以将keySet()转换为iterables

    Map<Object, Set<String>> history = Database.getHistory();

    Iterable<Object> keys = JavaConversions.asJavaIterable(history.keySet());

    for (Object key : keys) {
        int k = (int)key;
        System.out.printf("%d-%s\n", k, history.get(k).get().toString());
    }
Map history=Database.getHistory();
Iterable keys=JavaConversions.asJavaIterable(history.keySet());
用于(对象关键点:关键点){
int k=(int)键;
System.out.printf(“%d-%s\n”,k,history.get(k.get().toString());
}
对于Int问题,我可以在scala代码中将scala.Int更改为java.Integer,但对象似乎工作正常

对于排序键,根据来自的提示,我可以只填充键

    List<Integer> sortedList = new ArrayList<>();
    for (Object i : keys) {
        sortedList.add((int)i);
    }
    Collections.sort(sortedList);

    for (int key : sortedList) {
        System.out.printf("%d-%s\n", key, history.get(key).get().toString());
    }
List sortedList=new ArrayList();
用于(对象i:关键点){
分类列表。添加((int)i);
}
收集.分类(分类列表);
用于(int键:sortedList){
System.out.printf(“%d-%s\n”,键,history.get(键).get().toString());
}
这是一个

Scala中的强制效果很好,如下所述:

  import scala.collection.JavaConverters._
  private var history: mm[Int, mSet[String]] = mm[Int, mSet[String]]()
  history += ((42, mSet("hi")))
  def getMystery(): java.util.Map[Int, mSet[String]] = history.asJava
  def getHistory() = history.asJava.asInstanceOf[java.util.Map[Integer, mSet[String]]]
这是

Scala中的强制效果很好,如下所述:

  import scala.collection.JavaConverters._
  private var history: mm[Int, mSet[String]] = mm[Int, mSet[String]]()
  history += ((42, mSet("hi")))
  def getMystery(): java.util.Map[Int, mSet[String]] = history.asJava
  def getHistory() = history.asJava.asInstanceOf[java.util.Map[Integer, mSet[String]]]
这是

Scala中的强制效果很好,如下所述:

  import scala.collection.JavaConverters._
  private var history: mm[Int, mSet[String]] = mm[Int, mSet[String]]()
  history += ((42, mSet("hi")))
  def getMystery(): java.util.Map[Int, mSet[String]] = history.asJava
  def getHistory() = history.asJava.asInstanceOf[java.util.Map[Integer, mSet[String]]]
这是

Scala中的强制效果很好,如下所述:

  import scala.collection.JavaConverters._
  private var history: mm[Int, mSet[String]] = mm[Int, mSet[String]]()
  history += ((42, mSet("hi")))
  def getMystery(): java.util.Map[Int, mSet[String]] = history.asJava
  def getHistory() = history.asJava.asInstanceOf[java.util.Map[Integer, mSet[String]]]

是否显示
getHistory
函数?(上面有一个返回类型注释)@Chris Martin:这只是一行“历史”,历史的类型是mm[Int,mSet[String]],其中mm是可变映射,mSet是可变集。如果看不到上下文,我们无法确定推断的返回类型是什么。显示更多代码会有所帮助。是否显示
getHistory
函数?(用retu