相当于Java .NET动作&LT的; T>以及FUNC< T,U>中等 [英] Java equivalent of .NET Action<T> and Func<T,U>, etc

查看:133
本文介绍了相当于Java .NET动作&LT的; T>以及FUNC< T,U>中等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有标准的通用的回调或Java的功能/法类型,如 System.Action< T> 系统。 FUNC< T,U> 在.NET

Are there any standard generic "callback" or "function/method" types in Java, like System.Action<T> or System.Func<T,U> in .NET?

在我的具体情况,我需要包装了一个方法,它的类型之一(通用)参数 T 返回任何一类(即无效)。

In my concrete case, I need a class that wraps a method that takes one (generic) parameter of type T and returns nothing (i.e. void).

是的,这是很容易为自己创建一个这样的类/接口,但我preFER标准库类(如果有)。

Yes, it's easy enough to create such a class/interface for myself, but I'd prefer a standard library class if there is one.

推荐答案

我不相信有什么事在标准库这样的,没有。其他库有他们 - 比如Guice的提供&LT; T&GT; 和番石榴的功能&LT; F,T&GT; 公司&LT; T&GT; predicate&LT; T&GT; ...因此,如果你使用的库已经,您可能希望寻找到他们所提供的这个方向。

I don't believe there's anything in the standard library like this, no. Other libraries have them - things like Guice's Provider<T> and Guava's Function<F, T>, Supplier<T> and Predicate<T>... so if you're using libraries already, you might want to look into what they provide in this direction.

(编辑:如前所述,这些都是接口,该接口返回的东西 - 如此的相似, Func键&LT; T,U&GT; 不过的没有的类似动作&LT; T&GT;

( As noted, those are interfaces which return things - so similar to Func<T, U> but not similar to Action<T>.)

这篇关于相当于Java .NET动作&LT的; T&GT;以及FUNC&LT; T,U&gt;中等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆