I want to use java to call golang grpc.I used the old golang's consumer_proto.proto to gen java code
protoc --java_out=/home/xxx/src/main/java custom_proto.proto
protoc --plugin=protoc-gen-grpc-java=/home/xxx/protoc-gen-grpc-java-1.7.0-linux-x86_64.exe --grpc-java_out=/home/xxx/main/java custom_proto.proto
I success gen my proto java file.but I find use Inline object prompt syntax error,the problem is from:
message RepGetClassBySchoolD {
RequestRClassStruct Class = 1;
}
the error is:
getClass() in xx classes in 'java.lang.Object';attempting to use incompatible return type
when I run the code,The error is:
Error:(92, 62) java: com.xxx.RepGetClassBySchoolD getClass() Unable to cover java.lang.Object's getClass()
The method to be overwritten is final
It happend at class RepGetClassBySchoolD:
public com.class100.service.usercenter.RequestRClassStruct getClass() {
return class_ == null ? com.class100.service.usercenter.RequestRClassStruct.getDefaultInstance() : class_;
}
Is there a way to make this work? Or any ideas? thanks
I solved the problem. Fix it by:
message CascadeStuGRPC {
RequestRStudentStruct requestRStudentStruct =1 ;
RequestRTeachingAssistantStruct requestRTeachingAssistantStruct = 2;
RequestRSchoolStruct SchoolLogin = 3;
RequestRClassStruct Class = 4;
}
message RepGetClassBySchoolD {
RequestRClassStruct Class = 1;
}
It's just because what I define two message with common name "Class",I have been using this in golang for a long time, and it will not go wrong,but in proto-gen-jave it,It will produce this error.
just fix it by another name like this:
message CascadeStuGRPC {
RequestRStudentStruct requestRStudentStruct =1 ;
RequestRTeachingAssistantStruct requestRTeachingAssistantStruct = 2;
RequestRSchoolStruct SchoolLogin = 3;
RequestRClassStruct ClassCa = 4;
}
message RepGetClassBySchoolD {
RequestRClassStruct ClassSch = 1;
}
it gen like this:
public com.class100.service.usercenter.RequestRClassStruct getClassCa() {
return classCa_ == null ? com.class100.service.usercenter.RequestRClassStruct.getDefaultInstance() : classCa_;}
It gen getClassCa() not getClass(),This problem is solved.