gpt4 book ai didi

c# - Java 1.7 与 C# List/Set/Map 语法糖

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:33:29 29 4
gpt4 key购买 nike

以下应该是 Java 1.7 的一部分:

List<String> list = ["item"];
String item = list[0];

Set<String> set = {"item"};

Map<String, Integer> map = {"key" : 1};
int value = map["key"];

在 C#(和 VB.NET)中几乎可以完成同样的工作,但语法略有不同。在 .NET 中,这被实现为 indexed properties ,这是任何开发人员都可以用来应用到自己的类的语言功能。

有谁知道这些功能是否针对 List、Set 和 Map 及其子类严格硬编码,或者这背后有更通用的语言功能?

最佳答案

这些特性都没有进入 JDK7。列出了削减的 Java 语言更改 here作为:

JSR 334: Small language enhancements (Project Coin). A set of small language changes intended to simplify common, day-to-day programming tasks: Strings in switch statements, try-with-resources statements, improved type inference for generic instance creation ("diamond"), simplified varargs method invocation, better integral literals, and improved exception handling (multi-catch)

剩余的“Project Coin”特性和其他语言变化被用于 JDK8:

JSR 294: Language and VM support for modular programming. Enhancements to the Java language and virtual-machine specifications to support modular programming, at both compile time and run time

JSR 308: Annotations on Java types. An extension to the Java annotation syntax to permit annotations on any occurrence of a type

JSR TBD: Language support for collections. Literal expressions for immutable lists, sets,

JSR TBD: Project Lambda. Lambda expressions (informally, "closures") and defender methods for the Java programming language

关于c# - Java 1.7 与 C# List/Set/Map 语法糖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6531625/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com