dousha1873 2017-11-07 03:25
浏览 131

protoc-gen-java代码使用内联对象提示语法错误

describe

I want to use java to call golang grpc.I used the old golang's consumer_proto.proto to gen java code

process

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

result

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

  • 写回答

1条回答 默认 最新

  • duanlinjian5819 2017-11-07 03:56
    关注

    I solved the problem. Fix it by:

    reason:

    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.

    fix:

    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.

    评论

报告相同问题?