In other words, annotations as a concept do not exist. And that's why it is hard to understand, in general what an annotation is: because there is no common feature linking all annotations that could be used to put them in a conceptual group. These have nothing to do with one another except for starting with an symbol.īasically, what appears to have happened is that some committee responsible for maintaining the java language definition is gatekeeping the addition of new keywords to the java language, and therefore other developers are doing an end run around that by calling new keywords "annotations". There is the annotation, which is used to specify what kinds of objects a user defined annotation (a third type of construct with nothing in common with other kinds of annotation) can be attached to. There is, in other words, nothing that binds them together into an abstract conceptual group other than the fact that they all start with an symbol.įor example, there is the annotation, which tells the compiler to check that this member function overrides one in the parent class. The first thing a newcomer to annotations will ask about annotations is: "What is an annotation?" It turns out that there is no answer to this question, in the sense that there is no common behavior which is present in all of the various kinds of java annotations. Also, they only work on class level, not on method level. NET coding guidelines say not to use tag interfaces. EDIT: Attributes on classes are comparable to tag interfaces (like Serializable in Java). They also control how the IDE form designer works. NET this is used by the compiler to generate (de)serialization information for classes, determine the memory layout of structures and declare function imports from legacy libraries (among others). I don't know any examples in Java but in. When you reflect a type of a class in your code, you can access the attributes and act according to the information found there. Similarly, methods can be marked obsolete. One typical Java example, has no effect on the code but it can be used by the compiler to generate a warning (or error) if the decorated method doesn't actually override another method. No, but VB and C# have attributes which are the same thing. Also, are they unique to Java, is there a C++ equivalent?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |