简体   繁体   English

解决protobuf java生成文件中的override编译错误

[英]Solve override compilation error in protobuf java generated files

I have the following setup:我有以下设置:

I have the following dependency in my POM:我的 POM 中有以下依赖项:

<dependency>
    <groupId>com.google.protobuf</groupId>
    <artifactId>protobuf-java</artifactId>
    <version>3.14.0</version>
</dependency>

I have a very simple proto file:我有一个非常简单的原型文件:

syntax = "proto3";
package com.ziath.genericdecoderserver;
option java_outer_classname = "DecodePackage";

message DecodeData {
    string template = 1;
    bytes image = 2;
    int32 startColumn = 3;
    int32 endColumn = 4;
}

I'm generating the proto file using the version 3.14.0, binary for win64:我正在使用版本 3.14.0 生成 proto 文件,win64 的二进制文件:

PS C:\Users\neilb\Documents\GitHub\GenericDecoderServer\src\main\protobuf\bin> .\protoc.exe --version
libprotoc 3.14.0

This matches the maven dependency I'm pulling in. However the file generated has error with the override annotation:这与我要引入的 maven 依赖项匹配。但是,生成的文件在覆盖注释中存在错误:

@java.lang.Override
public com.ziath.genericdecoderserver.DecodePackage.DecodeData buildPartial() {
    com.ziath.genericdecoderserver.DecodePackage.DecodeData result = new 
    com.ziath.genericdecoderserver.DecodePackage.DecodeData(this);
    result.template_ = template_;
    result.image_ = image_;
    result.startColumn_ = startColumn_;
    result.endColumn_ = endColumn_;
    onBuilt();
    return result;
}

The reported error is:报告的错误是:

The method buildPartial() of type DecodePackage.DecodeData.Builder must override a superclass method

So this method is in the Builder class which is defined as:所以这个方法在 Builder class 中定义为:

    public static final class Builder extends com.google.protobuf.GeneratedMessageV3.Builder<Builder> implements
        // @@protoc_insertion_point(builder_implements:com.ziath.genericdecoderserver.DecodeData)
    com.ziath.genericdecoderserver.DecodePackage.DecodeDataOrBuilder {

Eclipse is correct the method buildPartial is not in either of the interfaces protobuf is referencing so it looks like a version mismatch but the versions are the same. Eclipse 是正确的,方法 buildPartial 不在 protobuf 引用的任何一个接口中,因此看起来版本不匹配,但版本相同。 There are scores of errors in this generated code along the same lines.此生成的代码中存在许多错误。 Does anybody know what the problem is or even seen this before because my searches show nothing from this?有没有人知道问题是什么,甚至以前见过这个,因为我的搜索没有显示任何内容?

Thanks.谢谢。

Cheers,干杯,

Neil尼尔

Solved it.解决了。 The project was created using Spring Initilaser and for some reason that made the java version to be 1.5 in eclipse.该项目是使用 Spring Initilaser 创建的,由于某种原因,java 版本在 eclipse 中为 1.5。 1.5 does not allow override for interface methods. 1.5 不允许覆盖接口方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM