【问题标题】:No instance(s) of type variable(s) exist so that String conforms to Message不存在类型变量的实例,因此 String 符合 Message
【发布时间】:2022-10-18 15:01:10
【问题描述】:

我有一个名为“key”的字段,类型为google.protobuf.Any。我知道这是一个字符串,所以我想使用unpack() 方法“转换”它。

然而,当我写request.getKey().unpack(String.class) 时,我得到一个编译错误:

Required type: Class<T>
Provided: Class<String>
reason: no instance(s) of type variable(s) exist so that String conforms to Message

我真的不明白这到底是什么意思。

这是我的原型文件:

message SearchCriteria{
  google.protobuf.Any key = 1;
  string storeName = 2;
}

【问题讨论】:

    标签: java protocol-buffers grpc-java


    【解决方案1】:

    您需要使用一些 protobuf 类型: &lt;T extends com.google.protobuf.Message&gt;

    【讨论】:

      猜你喜欢
      • 2019-12-16
      • 2017-12-04
      • 1970-01-01
      • 2017-04-22
      • 1970-01-01
      • 2020-07-13
      • 1970-01-01
      • 2020-11-04
      • 1970-01-01
      相关资源
      最近更新 更多