赋值运算符重载Java [英] Assignment Operator Overloading Java
本文介绍了赋值运算符重载Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难弄清楚如何实现将C ++中的赋值运算符重载到Java的等效方法.我知道没有这种东西,但是我需要对其进行模拟.我试过重写Clone()函数,但是没有运气.有什么想法吗?
Im having trouble figuring out how to implement the equivalent of overloading the assignment operator in C++ to Java. I know there is no such thing, but I need to simulate it. I've tried overriding the Clone() function, but no luck. Any ideas?
下面是我的主要
Queue p = new Queue();
Queue q = new Queue();
p.enqueue('a');
p.enqueue(9);
p.enqueue(10);
p.enqueue(310);
p.enqueue(8);
q = p;
System.out.print(p);
这是克隆函数
public void Clone(Queue other) throws Throwable
{
System.out.println("test\n");
if(this == other)
{
}
else
{
while(!isEmpty())
dequeue();
Node tmp = other.head;
while(tmp != null){
this.enqueue((T)tmp.element);
tmp = tmp.next;
}
}
}
推荐答案
Java不支持运算符重载.
Operator overloading is Not supported by Java.
操作符重载违反了Java语言设计的中心原则之一:透明性.试图使操作员超载是违反语言哲学的,应避免...
Operator overloading violates one of the central tenets of the Java language design : transparency. It is against the language philosophy trying to overload an operator and should be avoided ...
这篇关于赋值运算符重载Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文