简体   繁体   English

Nice编程语言作为Java泛型的替代品

[英]the Nice programming language as an alternative to Java generics

I've been reading Bruce Eckel's Thinking In Java and in the chapter on generics, he briefly mentions the Nice programming language as something that handles parametrized types better than Java, but compiles into Java bytecode. 我一直在阅读Bruce Eckel的Thinking In Java和关于泛型的章节,他简要地提到Nice编程语言比Java更好地处理参数化类型,但编译成Java字节码。

Does anyone have any experience with this? 有人对这个有经验么? Generics make my head hurt, so the prospect of an alternative that interoperates with Java is appealing... but I sort of feel like it would be like trying to learn both French and Quebecois and getting yelled at if I get them mixed up in the wrong context. 仿制药让我头疼,因此与Java互操作的替代品的前景是吸引人的...但我觉得这就像尝试学习法语和魁北克一样,并且如果我把它们混淆在一起就会大吼大叫错误的背景。 (no offense meant so please don't ding me for not being PC) And whoever thought up the name "Nice" should be shot, since it makes it impossible to search for any websites other than the sourceforge one. (没有冒犯意味着所以请不要因为不是PC而骂我)并且想出“Nice”这个名字的人应该被枪杀,因为这样就无法搜索除sourceforge之外的任何网站。

I'd also suggest looking at Scala , a multi-paradigm (OO and functional) language that runs on the JVM. 我还建议查看Scala ,这是一种在JVM上运行的多范式(OO和功能)语言。 Martin Odersky, the "father of Scala" was also a primary contributor to the implementation of generics in Java, including his work on the Pizza and GJ implementations. “Scala之父”Martin Odersky也是Java中泛型实现的主要贡献者,包括他在Pizza和GJ实现方面的工作。

The current type-erasure mechanism in Java does force one to understand some implementation details to make sense of restrictions, but it is fair to say that using full-blown generic support in any language is going to require a learning curve. Java中当前的类型擦除机制确实迫使人们理解一些实现细节以理解限制,但可以公平地说,在任何语言中使用全面的通用支持都需要学习曲线。

I found Java Generics and Collections to be a well-written introduction and guide to using generics in Java 5. 我发现Java Generics和Collections是一本精心编写的Java 5中使用泛型的简介和指南。

Maybe the question to ask is, "Why do generics make your head hurt?" 也许要问的问题是,“为什么仿制药会让你头痛?” How are you using them that causes such pain? 你如何使用它们导致这种疼痛?

I'll agree that there are flaws with generics in Java, and there are situations (eg, extends) that do cause problems, but what exactly is your issue? 我同意Java中的泛型存在缺陷,并且存在导致问题的情况(例如,扩展),但究竟是什么问题?

Using another language that compiles to byte code might help you in the short run, but if you're working in a team that delivers systems that others will have to maintain you might have problems introducing a technology like Nice, no matter how elegant it is. 使用另一种编译为字节代码的语言可能会在短期内帮助您,但如果您在一个提供其他人必须维护的系统的团队中工作,您可能会在引入像Nice这样的技术时遇到问题,无论它多么优雅。

I'd say look at Scala or Groovy. 我会说看Scala或Groovy。 It's my impression that Nice is an experimental language that never caught traction. 我的印象是,尼斯是一种从未吸引力的实验性语言。 If you don't like Java's generics at all, then you might prefer groovy, which is dynamically typed. 如果您根本不喜欢Java的泛型,那么您可能更喜欢groovy,它是动态类型的。 If you like the idea of generics, but find Java's implementation of them confusing (like I do), then you might like scala, which handles generics more sensibly. 如果你喜欢泛型的想法,但是发现Java的实现令人困惑(就像我一样),那么你可能会喜欢scala,它可以更明智地处理泛型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM