In package com.google.protobuf
I found a Message
interface, it claims it will compare by content:
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);
But I write test code:
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());
}
}
It gives false
.
So, how to compare to proto buffer message?