一、实现Flink提供的接口
class MyMapFunction implements MapFunction<String, Integer>{
public Integer map(String value){
return Integer.parseInt(value);
}
};
二、使用匿名类
data.map(new MapFunction<String, Integer>(){
public Integer map(String value){
return Integer.parseInt(value);
}
});
三、使用Java8的Lambda表达式
data.filter(s -> s.startsWith("http://"));
data.reduce((i1,i2) -> i1 + i2)
四、使用富函数
class MyMapFunction extends RichMapFunction<String, Integer>{
public Integer map(String value) {
return Integer.parseInt(value);
}
}
data.map(new MyMapFunction());
data.map(new RichMapFunction<String, Integer>(){
public Integer map(String value){
return Integer.parseInt(value);
}
})