java中的finagle

编程入门 行业动态 更新时间:2024-10-25 03:30:29
java中的finagle - Function,Function1等(finagle in java - Function, Function1 etc)

如何在Java中使用finagle的Future对象的flatMap方法创建Function1对象?

试过这个:

Function1<String, String> f = new Function1<String, String>() { @Override public String apply(String s) { return null; } };

但它不起作用:

错误:(22,73)java:不是抽象的,并且不会覆盖抽象方法而是scala.Function1中的$ mcVJ $ sp(scala.Function1)

How do I create Function1 object for use in flatMap method of finagle's Future object in Java?

Tried this:

Function1<String, String> f = new Function1<String, String>() { @Override public String apply(String s) { return null; } };

But it doesn't work:

Error:(22, 73) java: is not abstract and does not override abstract method andThen$mcVJ$sp(scala.Function1) in scala.Function1

最满意答案

为了完整起见,这是我上面两个月的评论的答案。

首先是一些进口:

import scala.Function1; import scala.runtime.AbstractFunction1;

现在你只需要定义apply方法:

Function1<String, String> f = new AbstractFunction1<String, String>() { public String apply(String s) { return s; } };

但是,如果您正在使用Finagle, Twitter的Util库也提供了类似的帮助类:

import com.twitter.util.Function; import scala.Function1;

接着:

Function1<String, String> f = new Function<String, String>() { public String apply(String s) { return s; } };

后一种选择可能更好 - 我从未真正喜欢使用scala.runtime东西。

For the sake of completeness, here's the answer from my two month-old comment above.

First for some imports:

import scala.Function1; import scala.runtime.AbstractFunction1;

And now you only have to define the apply method:

Function1<String, String> f = new AbstractFunction1<String, String>() { public String apply(String s) { return s; } };

If you're using Finagle, though, Twitter's Util library also provides a similar helper class:

import com.twitter.util.Function; import scala.Function1;

And then:

Function1<String, String> f = new Function<String, String>() { public String apply(String s) { return s; } };

This latter option is probably better—I've never really liked explicitly using stuff from scala.runtime.

更多推荐

本文发布于:2023-08-01 09:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1356743.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:java   finagle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!