以点

时间:2017-02-18 03:39:15

标签: java

我还没有用Java编程一段时间,我在Apache Kafka教程中遇到了这段代码。我不明白这些陈述的开头是什么点。这是否意味着创建一个类型为KTable的新变量'wordCounts',分配textLines,然后调用wordCounts.flatMapValues(),wordCounts.map(),然后调用wordCounts.countByKey()?我在Javascript中也看到了这种符号,但我不知道它叫什么。:

   KTable wordCounts = textLines
    // Split each text line, by whitespace, into words.
    .flatMapValues(value -> Arrays.asList(value.toLowerCase().split("\\W+")))

    // Ensure the words are available as record keys for the next aggregate operation.
    .map((key, value) -> new KeyValue<>(value, value))

    // Count the occurrences of each word (record key) and store the results into a table named "Counts".
    .countByKey("Counts")

3 个答案:

答案 0 :(得分:2)

此:

TimelinePanel

实际上与此相同:

KTable wordCounts = textLines
// Split each text line, by whitespace, into words.
.flatMapValues(value -> Arrays.asList(value.toLowerCase().split("\\W+")))

空格和注释对编译器来说并不重要,“点”只是取消引用最后一个符号,即变量KTable wordCounts = textLines.flatMapValues(value -> Arrays.asList(value.toLowerCase().split("\\W+")))

答案 1 :(得分:1)

语句以textLines开头,然后在下一行继续,但在textLines上调用方法flatMapValues。然后map编辑并计算。此样式有时称为fluent interface

答案 2 :(得分:0)

他们只是调用与textLines 相关联的flatMapValues方法 .flatMapValues不在起跑线上,为了更好地澄清代码,他们刚刚输入以保持新的界限。在JAVA的起点中没有用(点)开始方法的概念或也用任何语言