.NET Attributes versus Java Annotations: Which Cam

2020-08-12 09:05发布

问题:

I'm a .NET developer learning Java EE. These two concepts seem to serve the same exact purposes in either system.

So which framework gets credit for inventing them?

回答1:

.NET metadata was, I believe, introduced in .NET 1.1 which was released 3 April 2003 (it appears to be already in before that?). The Java annotations were proposed as JSR-175 on 19 March 2002 which was approved on 30 September 2004 and became part of Java SE 5.0 which was released the same day.

It's unclear when exactly .NET metadata was proposed, but when it comes to the first release, .NET wins.



回答2:

Attributes have been part of the CLR since its inception. I have an old prerelease spec of C# printed out from November 1999 that describes them, but the earliest reference I can find is the C# 1.0 spec from 2001. This was clearly several years before the feature was added to Java.

EDIT: The book, C# Programming with the Public Beta, was published in 2000 and mentions attributes.



回答3:

I believe they came first with .NET; Java 5 followed.

Java has unfortunately been behind the curve on language improvents despite the fact it was the language C# was modeled after.

Pierreten's comment is correct, but I think there are several factors that explain it:

  1. Java has a longer legacy than .NET, and maintaining backward compatibility is a high priority
  2. Java community process takes longer to build consensus; Microsoft doesn't need any such consensus if it believes a feature is needed.
  3. Sun's financial decline and eventual purchase by Oracle meant fewer resources were available to devote to Java.
  4. Sun has lost the minds that drove Java forward at its height (e.g., Bill Joy, James Gosling). Anders Hejlsberg and Eric Lippert are still with Microsoft.

(Eric Lippert left Microsoft in Jan 2013 to join Coverity.)