我一直在想如何将下面的lambda表达式(这是Java8最大的语言特性)转换为相应的Java 7
final JmsBolt jmsBolt = new JmsBolt();
jmsBolt.setJmsMessageProducer((session, input) -> {
final String json = "{\"stateCode\":\"" + input.getString(0) + "\", \"sentiment\":" + input.getInteger(1) + "}";
return session.createTextMessage(json);
这是JmsBolt类:
public class JmsBolt extends BaseRichBolt {
...
public void setJmsMessageProducer(JmsMessageProducer producer){
this.producer = producer;
}
...
}
这是JmsMessageProducer功能界面:
public interface JmsMessageProducer extends Serializable{
public Message toMessage(Session session, Tuple input) throws JMSException;
}
答案 0 :(得分:2)
我认为匿名课程可以帮助你:
jmsBolt.setJmsMessageProducer(new JmsMessageProducer() {
@Override
public Message toMessage(Session session, Tuple input) {
...
}
});