重现此错误的详细步骤:
1)从https://github.com/protocolbuffers/protobuf/releases/download/v3.19.1/protoc-3.19.1-linux-x86_64.zip下载protoc v3.19.1
$ wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.1/protoc-3.19.1-linux-x86_64.zip
2)解压下载的protoc
$ unzip protoc-3.19.1-linux-x86_64.zip
$ cd protoc-3.19.1
3)编译以下helloworld.proto
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// The greeting service definition.
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
// The request message containing the user's name.
message HelloRequest {
string name = 1;
}
// The response message containing the greetings
message HelloReply {
string message = 1;
}
使用命令:
$ mkdir java_output
$ bin/protoc --java_output=java_output helloworld.proto
转到目录 java_output/io/grpc/examples/helloworld 并 grep com.google.protobuf.GenerateMessageV3.isStringEmpty
$ cd java_output/io/grpc/examples/helloworld
$ grep com.google.protobuf.GeneratedMessageV3.isStringEmpty *.java
HelloReply.java: if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) {
HelloReply.java: if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(message_)) {
HelloRequest.java: if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
HelloRequest.java: if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) {
com.google.protobuf.GenerateMessageV3 类中的受保护方法 isStringEmpty 由类 HelloReply 和 HelloRequest 使用。当尝试编译上面生成的源代码时,我们收到错误:
error: cannot find symbol
if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(appId_)) {
^
symbol: method isStringEmpty(Object)
location: class GeneratedMessageV3