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

Java flink文档中给出的代码不可编译,java,hadoop,apache-flink,Java,Hadoop,Apache Flink,我对flink很陌生,正在尝试flink文档中给出的一些代码 flink文档中的代码: public class WordWithCount { public String word; public long count; public WordWithCount() {} public WordWithCount(String word, int count) { this.word = word; this.count =

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

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"
公共类WordWithCount{
公共字符串;
公众长时间计数;
public WordWithCount(){}
公用字WithCount(字符串字、整数计数){
这个单词=单词;
this.count=计数;
}
}
DataStream wordCounts=env.fromElements(
新单词WithCount(“你好”,1),
新单词WithCount(“世界”,2));
wordCounts.keyBy(“word”);//按字段的关键字表达式“word”
但我得到的类型不匹配错误在

DataStream<Tuple2<String, Long>> wicstream = sev.fromElements(new WordwithCount("Hello",1), new WordwithCount("hello",1)); 
DataStream wicstream=sev.fromlelements(newwordwithcount(“Hello”,1),newwordwithcount(“Hello”,1));
错误消息:

Type mismatch: cannot convert from DataStreamSource<WordwithCount> to DataStream<Tuple2<String,Long>>
类型不匹配:无法从DataStreamSource转换为DataStream

请帮助我理解我的错误。

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

您的代码应该如下所示:

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

正确!!但是我提到的代码是在flink documnetation中,你认为文档中的代码是错误的吗?我从部分中选择了这个代码:Pojosoh现在我明白了。用链接编辑你的主要帖子。是的,我认为这个例子是错误的。您可以尝试发布到用户列表,开发人员通常响应非常快。@AnkitJindal我已经用修复程序创建了pull请求。给了你一个发现的荣誉:)