Java的无功扩展(Reactive Extensions for Java)

编程入门 行业动态 更新时间:2024-10-24 01:50:30
Java的无功扩展(Reactive Extensions for Java) java

是否有任何等效的Java的Reactive Extensions (.NET)?

关于Rx(反应式扩展)

Rx是一个使用可观察集合来编写异步和基于事件的程序的库。

我知道规则引擎如JBOSS的Drools ,但是有没有更接近Microsoft .NET方法的其他方法?

Is there any equivalent of Reactive Extensions (.NET) for Java?

About Rx (Reactive Extensions)

Rx is a library for composing asynchronous and event-based programs using observable collections.

I am aware of rule engines such as Drools from JBOSS, but is there some other way that is closer to the Microsoft .NET approach?

最满意答案

我不知道其中之一 - 坦率地说,这样做很难做到这么整洁。 穿线方面很好; Java在线程化方面完全有能力......但目前,该语言不支持相应的功能。

LINQ的一个很好的设计特性是,一切都基于接口,然后使用扩展方法来增加额外的功能。 这允许代码流利地阅读 - 想象一下,如果你必须写:

IObservable<int> = Observable.Select( Observable.Where( source, x => x.SomeCondition) x => x.SomeProjection);

伊克。 扩展方法更优美:

IObservable<int> = source.Where(x => x.SomeCondition) .Select(x => x.SomeProjection);

现在Java版本可以基于抽象基类,但是这会失去一些优雅。

接下来是lambda表达式和方法组转换 - 这些对于LINQ来说是非常重要的。 Java中最接近的等价类(匿名内部类)在C#中使用lambda表达式时无处不在。

基本上,Rx的Java版本将是可行的,但它不会像C#版本那样优雅 - 这可能是为什么它没有被完成,据我所知。 Java可能还有其他“异步驱动”库,但它们不可能像Rx那样全面和整齐。

Java 7中的更改可能会使这更加可行; 据我所知,扩展方法没有被引入,但是如果lambda语法最终没问题的话,抽象基类版本是合理的...

I'm not aware of one - and frankly it would be hard to do in such a neat fashion. The threading side is fine; Java's perfectly capable when it comes to threading... but at the moment, the language just doesn't support the appropriate features.

One of the neat design features of LINQ is that everything is based on interfaces and then extension methods are used to add extra functionality. That allows code to read fluently - imagine if you had to write:

IObservable<int> = Observable.Select( Observable.Where( source, x => x.SomeCondition) x => x.SomeProjection);

Ick. The extension method is much more graceful:

IObservable<int> = source.Where(x => x.SomeCondition) .Select(x => x.SomeProjection);

Now a Java version could be based on an abstract base class instead, but that would lose some of the elegance.

Next come lambda expressions and method group conversions - these really are fundamental to LINQ in general; the closest equivalent in Java (anonymous inner classes) are too ugly to be used everywhere you'd use a lambda expression in C#.

Basically, a Java version of Rx would be feasible, but it wouldn't be nearly as elegant as the C# version - which is probably why it hasn't been done as far as I'm aware. There may be other "asynchrony-driven" libraries around for Java, but they're unlikely to be as comprehensive and neat as Rx.

It's possible that the changes in Java 7 will make this more feasible; as far as I know extension methods aren't being introduced, but an abstract base class version would be reasonable if the lambda syntax ends up being okay...

更多推荐

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

发布评论

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

>www.elefans.com

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