1、scala语法中将java的接口当作类去使用
@FunctionalInterface
@Public
public interface ReduceFunction<T> extends Function, Serializable {
T reduce(T var1, T var2) throws Exception;
}
class MyReduceFunction extends ReduceFunction[SensorReading] {
override def reduce(t: SensorReading, t1: SensorReading): SensorReading = {
SensorReading(t.id, t1.timestamp, t.temperature.min(t1.temperature))
}
}
ReduceFunction的接口需要继承才能使用
@PublicEvolving
public interface ValueState<T> extends State {
T value() throws IOException;
void update(T var1) throws IOException;
}
将ValueState作为类的类型使用
var lastValueState: ValueState[Double] = _
2、Unit代表返回为空
override def open(parameters: Configuration): Unit = {
lastValueState = getRuntimeContext.getState(new ValueStateDescriptor[Double]("tempState", classOf[Double]))
}
|