提供 Java 特征的库或语言扩展?

发布于 2024-10-20 21:29:04 字数 223 浏览 1 评论 0原文

我刚刚了解了特征(Smalltalk 中的“特征”,Perl 中的“角色”)。我想用我熟悉的语言快速尝试它们。 Java 中是否有支持特征的库或扩展?

我听说 AspectJ 和 Qi4J 都支持 mixins,但我也了解到 mixins 与特征不同。那么我也可以使用这些库之一来获取特征吗?

或者 Scala 怎么样,它完全向后兼容 Java,对吧?这支持特质吗?

还有其他建议吗?

I've just been introduced to traits ("traits" in Smalltalk, "roles" in Perl). I'd like to experiment with them quickly, in a language I'm familiar with. Are there any libraries or extensions in Java that support traits?

I've heard that AspectJ and Qi4J both support mixins, but I've also read that mixins are different from traits. So can I also use one of those libraries for traits?

Or how about Scala, that's fully backward compatible with Java, right? Does that support traits?

Any other suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蘑菇王子 2024-10-27 21:29:04

或者 Scala 怎么样,它完全向后兼容 Java,对吧?这支持特质吗?

是的,Scala 完全支持 Traits。它必须跳过一些奇怪的环节才能与 JVM 一起工作,但它就在那里,而且非常强大。

您可以在 Scala 中编写实验,它将与您现有的 Java 内容进行互操作(取决于工具)

Or how about Scala, that's fully backward compatible with Java, right? Does that support traits?

Yes, Scala has full support for Traits. It has to jump through a few weird hoops to make it work with the JVM, but it's there, and it's very powerful.

You can write your experiment in Scala, and it'll interop with your existing Java stuff (tools depending)

陌伤浅笑 2024-10-27 21:29:04

Qi4j 2.0(正在开发中)增加了强大的 Scala 支持,我们正在努力使 Scala Traits 用作 Qi4j mixins 和关注点(AOP“around suggest”等价物)。
Scala 特征编译为静态方法,该方法采用所属类的代理实例作为第一个参数(C 中的经典 C++ 表示形式)。 Qi4j 将能够将 Trait 连接为 Mixin(即方法可以在 Composite 的公共接口中公开)并绑定在底层 StateHolder 中,以便 Trait 使用组合,因此看起来 Trait 具有状态...

FTR; Qi4j 2.0 还最大限度地减少了类型占用空间,从而允许比以前更多地使用与 Qi4j 无关的类型。

Qi4j 2.0 (in the works) adds strong Scala support, and we are working on making Scala Traits useful as Qi4j mixins and concerns (AOP "around advice" equivalents).
The Scala trait compiles down to static methods that takes a proxy instance of the owning class as the first argument (classic C++ representation in C). Qi4j will be able to wire up the the Trait as a Mixin (i.e. the methods can be exposed in the Composite's public interface) and bind in the underlying StateHolder for the composite to be used by the Trait, so it seems that traits will have state...

FTR; Qi4j 2.0 is also minimizing the type footprint, allowing for Qi4j-agnostic types to be used even more than before.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文