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?
C# attributes, are a new feature with no equivalent in Java.
An annotation on a program element (commonly a class, method, or field) is a piece of meta-data added to that program element which can be used to embellish that element with extra code. In Java this is called an annotation, in C# this is called an attribute.
Attributes are used for adding metadata, such as compiler instruction and other information such as comments, description, methods and classes to a program. The . Net Framework provides two types of attributes: the pre-defined attributes and custom built attributes.
In C#, attributes are classes that inherit from the Attribute base class. Any class that inherits from Attribute can be used as a sort of "tag" on other pieces of code. For instance, there is an attribute called ObsoleteAttribute . This is used to signal that code is obsolete and shouldn't be used anymore.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With