简体   繁体   English

Java意外类型错误必需变量找到值

[英]Java unexpected type Error Required Variable Found Value

public boolean replaceEventAt(String eventStr, int position){
  boolean answer = false;

  if((position > 0) && (position <= events.size())){
     events.get(position - 1) = eventStr;
     answer = true;
  }

  return answer;
}

Error on fifth line where Java complains that position is a value not a variable please help 在第五行出现错误,Java抱怨位置是一个值而不是变量,请帮忙

An assignment operates between what is known as an lvalue and an rvalue . 分配在称为lvaluervalue

lvalue stands for left-hand-side-value. lvalue代表左侧值。

rvalue stands for right-hand-side-value. rvalue代表右侧值。

The rvalue can be many things, like a variable, a constant, a function call expression, etc, but the left side must be assignable, so it cannot be a constant or a function call. 右值可以是很多东西,例如变量,常量,函数调用表达式等,但是左侧必须是可赋值的,因此它不能是常量或函数调用。

In your case, your rvalue is a function invocation; 在您的情况下,您的右值是一个函数调用; that won't work. 那行不通。 The compiler error message is saying exactly that. 编译器错误消息恰恰说明了这一点。

If we knew what you are trying to do we could perhaps explain more, but it is unclear from the code that you posted that it is that you want to accomplish. 如果我们知道您要尝试做的事情,我们也许可以进一步解释,但是从您发布的代码中并不清楚它是您想要完成的。 Perhaps events is some collection, and you want to set the element at position position - 1 to eventStr , in this case you would probably want events.set( position - 1, eventStr ); 也许events是某个集合,并且您想要将位置position - 1的元素设置为eventStr ,在这种情况下,您可能需要events.set( position - 1, eventStr );

Left hand side must be a variable (ie we should be able to assign a value to it ). 左侧必须是一个变量(即,我们应该能够为其分配一个值)。 But in your case it is performing a get operation So it is throwing an Error 但是在您的情况下,它正在执行get操作,因此会引发错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java错误消息。 意外类型,必需变量,发现值 - Java Error message. unexpected type, required variable, found value Java编译错误:意外类型要求:找到变量:值 - Java Compile Error: Unexpected Type required: variable found: value 所需的Java错误意外类型:变量; 找到:ArrayList中的值 - Java Error unexpected type required: variable; found: value in an ArrayList Java转换错误:意外类型。 必需:变量,找到:值 - Java casting error: unexpected type. required: variable, found: value 错误:意外类型,必需:变量并找到:值 - Error: unexpected type, required: variable and found: value Java:“意外类型; 必需:变量; 找到:值”,尝试返回一个值 - Java: “Unexpected Type; required: Variable; found: value” by trying to return a value 简单的Java加密/解密-(错误:意外类型||必需:找到的变量:值) - Simple Java Encryption/Decryption - (Error: unexpected type || required: variable found: value) 类运算符错误数组:所需的意外类型:找到的变量:值 - Array of Class Operator Error: unexpected type required: variable found: value 另一个作业问题错误意外类型是必需的:变量已找到:值 - another homework question error unexpected type required:variable found:value 意外类型,必需变量,找到值 - unexpected type required variable found value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM