flink的对象作为数据传输的要求

flink的对象作为数据传输的要求,第1张

flink的对象作为数据传输的要求

@org.apache.flink.api.common.InvalidProgramException: This type (GenericType

对于java 的对象要求;属性必须是public 的修饰符,必须添加无参数构造方法

报错之前类对象
  public  class WorldValueDesc {
        private String word; // 属性设置私有 错误1
        private int cnt;   // 属性设置私有 错误1
        //没有添加无参数构造方法 错误1
        public WorldValueDesc(String word, int cnt) {
            this.word = word;
            this.cnt = cnt;
        }

        public void setWord(String word) {
            this.word = word;
        }

        public void setCnt(int cnt) {
            this.cnt = cnt;
        }

        public String getWord() {
            return word;
        }

        public int getCnt() {
            return cnt;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            WorldValueDesc that = (WorldValueDesc) o;
            return cnt == that.cnt &&
                    Objects.equals(word, that.word);
        }

        @Override
        public int hashCode() {
            return Objects.hash(word, cnt);
        }

        @Override
        public String toString() {
            return "WorldValueDesc{" +
                    "word='" + word + ''' +
                    ", cnt=" + cnt +
                    '}';
        }
    }
修改以后代码

public class WorldValueDesc {
public String word;
public int cnt;

public WorldValueDesc() {
}

public WorldValueDesc(String word, int cnt) {
    this.word = word;
    this.cnt = cnt;
}

public void setWord(String word) {
    this.word = word;
}

public void setCnt(int cnt) {
    this.cnt = cnt;
}

public String getWord() {
    return word;
}

public int getCnt() {
    return cnt;
}

@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    WorldValueDesc that = (WorldValueDesc) o;
    return cnt == that.cnt &&
            Objects.equals(word, that.word);
}

@Override
public int hashCode() {
    return Objects.hash(word, cnt);
}

@Override
public String toString() {
    return "WorldValueDesc{" +
            "word='" + word + ''' +
            ", cnt=" + cnt +
            '}';
}

}

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5562838.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存