有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

flink文档中给出的java代码不可编译

我对弗林克很陌生,正在尝试弗林克文档中给出的一些代码

flink文档中的代码:

public class WordWithCount {

    public String word;
    public long count;

    public WordWithCount() {}

    public WordWithCount(String word, int count) {
        this.word = word;
        this.count = count;
    }
}

DataStream<Tuple2<String, Long>> wordCounts = env.fromElements(
    new WordWithCount("hello", 1),
    new WordWithCount("world", 2));

wordCounts.keyBy("word"); // key by field expression "word"

但我在

DataStream<Tuple2<String, Long>> wicstream = sev.fromElements(new WordwithCount("Hello",1), new WordwithCount("hello",1)); 

错误消息:

Type mismatch: cannot convert from DataStreamSource<WordwithCount> to DataStream<Tuple2<String,Long>>

请帮我理解我的错误


共 (1) 个答案

  1. # 1 楼答案

    DataStream应该是X类型,与您提供给fromElements()方法的对象类型相同。您提供了WordwithCount作为参数,因此DataStream的类型应该是WordwithCount

    您的代码应该如下所示:

    DataStream<WordwithCount> wicstream = sev.fromElements(new WordwithCount("Hello",1), new WordwithCount("hello",1));