Java 运算符+;参数类型Constante未定义

Java 运算符+;参数类型Constante未定义,java,Java,我试图做一个求和,但我总是得到那个类型的错误。OperateurBinair类接受两个Constante类型的参数,Constante是一个我在其中创建值的类(type=double) 替换 return Left + Right; 与 其中,getter是您实际尝试求和的任何值的getter方法。这还假设您有一个Constante的构造函数,它接受一个double参数。如果没有,您将需要以下内容: Constante sum = new Constante; sum.setter(Left.

我试图做一个求和,但我总是得到那个类型的错误。OperateurBinair类接受两个Constante类型的参数,Constante是一个我在其中创建值的类(type=double)

替换

return Left + Right;

其中,
getter
是您实际尝试求和的任何值的
getter
方法。这还假设您有一个
Constante
的构造函数,它接受一个
double
参数。如果没有,您将需要以下内容:

Constante sum = new Constante;
sum.setter(Left.getter() + Right.getter());
return sum;
(或者只添加一个接受双精度的构造函数。)

或者,您也可以向
Constante
添加一个方法来进行求和

public static Constante sum(Constante addend1, Constante addend2) {
    //do whatever logic you want for summing these and return a Constante 
    //with the new value
}
然后在您当前所在的班级中,您可以执行以下操作:

return Constante.sum(Left, Right);
替换

return Left + Right;

其中,
getter
是您实际尝试求和的任何值的
getter
方法。这还假设您有一个
Constante
的构造函数,它接受一个
double
参数。如果没有,您将需要以下内容:

Constante sum = new Constante;
sum.setter(Left.getter() + Right.getter());
return sum;
(或者只添加一个接受双精度的构造函数。)

或者,您也可以向
Constante
添加一个方法来进行求和

public static Constante sum(Constante addend1, Constante addend2) {
    //do whatever logic you want for summing these and return a Constante 
    //with the new value
}
然后在您当前所在的班级中,您可以执行以下操作:

return Constante.sum(Left, Right);
替换

return Left + Right;

其中,
getter
是您实际尝试求和的任何值的
getter
方法。这还假设您有一个
Constante
的构造函数,它接受一个
double
参数。如果没有,您将需要以下内容:

Constante sum = new Constante;
sum.setter(Left.getter() + Right.getter());
return sum;
(或者只添加一个接受双精度的构造函数。)

或者,您也可以向
Constante
添加一个方法来进行求和

public static Constante sum(Constante addend1, Constante addend2) {
    //do whatever logic you want for summing these and return a Constante 
    //with the new value
}
然后在您当前所在的班级中,您可以执行以下操作:

return Constante.sum(Left, Right);
替换

return Left + Right;

其中,
getter
是您实际尝试求和的任何值的
getter
方法。这还假设您有一个
Constante
的构造函数,它接受一个
double
参数。如果没有,您将需要以下内容:

Constante sum = new Constante;
sum.setter(Left.getter() + Right.getter());
return sum;
(或者只添加一个接受双精度的构造函数。)

或者,您也可以向
Constante
添加一个方法来进行求和

public static Constante sum(Constante addend1, Constante addend2) {
    //do whatever logic you want for summing these and return a Constante 
    //with the new value
}
然后在您当前所在的班级中,您可以执行以下操作:

return Constante.sum(Left, Right);

Constante
是一个对象,您不能添加对象(除了
String
,这是一个特例),因为它的含义会随着对象的变化而变化,如果它有意义的话

Constante
可能有一个方法
Constante.add(otherConstante)
或者如果它是您自己的类,您可以编写一个。
.add()
方法很可能会添加
Constante
中包含的任何数字值

或者,如果不需要对象行为,请停止使用类
Constante
,并开始使用double(或其他数字原语)

其他注释
按照惯例,
Left
等变量名不应以大写字母开头。类是大写的,变量是小写的。

Constante
是一个对象,您不能添加对象(除了
String
,这是一种特殊情况),因为如果它有意义的话,它的意义会随着对象的变化而变化

Constante
可能有一个方法
Constante.add(otherConstante)
或者如果它是您自己的类,您可以编写一个。
.add()
方法很可能会添加
Constante
中包含的任何数字值

或者,如果不需要对象行为,请停止使用类
Constante
,并开始使用double(或其他数字原语)

其他注释
按照惯例,
Left
等变量名不应以大写字母开头。类是大写的,变量是小写的。

Constante
是一个对象,您不能添加对象(除了
String
,这是一种特殊情况),因为如果它有意义的话,它的意义会随着对象的变化而变化

Constante
可能有一个方法
Constante.add(otherConstante)
或者如果它是您自己的类,您可以编写一个。
.add()
方法很可能会添加
Constante
中包含的任何数字值

或者,如果不需要对象行为,请停止使用类
Constante
,并开始使用double(或其他数字原语)

其他注释
按照惯例,
Left
等变量名不应以大写字母开头。类是大写的,变量是小写的。

Constante
是一个对象,您不能添加对象(除了
String
,这是一种特殊情况),因为如果它有意义的话,它的意义会随着对象的变化而变化

Constante
可能有一个方法
Constante.add(otherConstante)
或者如果它是您自己的类,您可以编写一个。
.add()
方法很可能会添加
Constante
中包含的任何数字值

或者,如果不需要对象行为,请停止使用类
Constante
,并开始使用double(或其他数字原语)

其他注释
按照惯例,
Left
等变量名不应以大写字母开头。类是大写的,变量是小写的。

Constante
是引用类型。可以应用
+
的唯一引用类型是
字符串
。您要添加其
字段的值。
常量
是一种引用类型。可以应用
+
的唯一引用类型是
字符串
。你想增加他们的价值