变量预期的 java 向量 [英] Variable expected java vector

查看:38
本文介绍了变量预期的 java 向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写用于交换 java.util.Vector 中的两个元素的代码.但是我在这一行遇到了这个错误:

I'm writing code for swapping two elements in a java.util.Vector. But I get to this error in this line:

public void swap(int i, int j) {
    Order temp = maxHeap.get(i);
    maxHeap.elementAt(i) = maxHeap.get(j); // variable expected 
    maxHeap.get(j) = temp; // variable expected
    swapCounter++;
}

那么,我应该如何更改矢量节点的元素?顺便说一句,Order 只是另一个类,它是 vector 的每个节点,maxHeap 是我的 vector.

So, how am I supposed to change the element of a vector node? BTW Order is simply another class which is each node of the vector and maxHeap is my vector.

推荐答案

您不能将函数调用的结果分配给右值;相反,您使用 Vector.setElementAt(E, int) 喜欢

You can't assign the results of a function call to a rvalue; instead you use Vector.setElementAt(E, int) like

public void swap(int i, int j) {
    Order temp = maxHeap.get(i);
    maxHeap.setElementAt(maxHeap.get(j), i);
    maxHeap.setElementAt(temp, j);
    swapCounter++;
}

这篇关于变量预期的 java 向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆