我想比较基于5元组的两个对象:srcAddr,dstAddr,srcPort,dstPort,protocol
这是我有的:
public class Flows implements Serializable, Comparable {
String srcAddr, dstAddr, srcPort, dstPort, protocol;
public int compareTo(Flows arg0) {
if(this.srcAddr == arg0.srcAddr &&
this.dstAddr == arg0.dstAddr &&
this.srcPort == arg0.srcPort &&
this.dstPort == arg0.dstPort &&
this.protocol == arg0.protocol)
return 0;
}
Run Code Online (Sandbox Code Playgroud)
}
但它不起作用.它说无法比较两个字符串.谁能帮我理解是什么问题?谢谢.
这是我的compareTo方法,但我仍然得到"缺少返回语句"警告.谁能告诉我我的代码有什么问题?
public int compareTo(Flows other) {
if(this.srcAddr.equals(other.srcAddr)){
if(this.dstAddr.equals(other.dstAddr)){
if(this.srcPort.equals(other.srcPort)){
if(this.dstPort.equals(other.dstPort)){
if(this.protocol.equals(other.protocol)){
return 0;
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud) java ×3