在包com.google.protobuf
我發現了一個Message
接口,它聲稱將通過內容比較:如何比較Java中的兩個proto緩衝區消息?
public interface Message extends MessageLite, MessageOrBuilder {
// -----------------------------------------------------------------
// Comparison and hashing
/**
* Compares the specified object with this message for equality. Returns
* <tt>true</tt> if the given object is a message of the same type (as
* defined by {@code getDescriptorForType()}) and has identical values for
* all of its fields. Subclasses must implement this; inheriting
* {@code Object.equals()} is incorrect.
*
* @param other object to be compared for equality with this message
* @return <tt>true</tt> if the specified object is equal to this message
*/
@Override
boolean equals(Object other);
但我寫測試代碼:
public class Test {
public static void main(String args[]) {
UserMidMessage.UserMid.Builder aBuilder = UserMidMessage.UserMid.newBuilder();
aBuilder.setQuery("aaa");
aBuilder.setCateId("bbb");
aBuilder.setType(UserMidMessage.Type.BROWSE);
System.out.println(aBuilder.build() == aBuilder.build());
}
}
它給false
。
那麼,如何比較原始緩衝區信息?
比較,如果你想調用'equals',你應該做的正是 - 您正在使用''== ...代替 –