lecture 10 - Enumerate , Java doc and annotations Flashcards
What is enum?
type/class is a special reference type that holds a set of predefined constants.
We don’t instantiate an enumerated class. Instead, get one pre-allocated fixed instance via ClassName.VALUE NAME
Java’s enum type can behave like normal classes, and can have
other attributes and methods in addition to their fixed values.
Enum example
enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}
enum convention
By convention, the variable names are all capitalised.
All constants defined in an enum type are implicitly public static final.
How are comments upported in java ?
single line comment // …
multiple lines comment /* … */
documentation comment /** … */
What happens to the comments during compilation?
During compilation, all the comments are ignored.
What is Javadoc?
A JDK tool automatically creates fancy HTML-based
documentation based on /** …*/ in your source files.
You can include special doc tags in the documentation comments that provide specific information used by JavaDoc to format the documentation pages. What are these tags ?
@author Provides information about the author.
@version Indicates the version number.
@since Indicate the version.
@param Provides the name and description of a method.
@return Provides a description of a method’s return value.
@throws Indicates exceptions that are thrown by a method.
What is the difference between simple comment and annotations ?
An annotation always starts with the symbol @ followed by the annotation name.
Annotations are checked by Java
compiler. (Different from the doc tag)
Predefined annotations ?
@Deprecated
@Override
@SuppressWarnings
Custom annotations could be defined by using @interface
What does the @Deprecated tag mean ?
@Deprecated - indicates a marked element should no longer be used. It is usually also documented using the Javadoc @deprecated tag
/**
* @deprecated ← a doc tag, not checked by compiler
* explanation of why it was deprecated
*/
@Deprecated ← an annotation, checked by compiler
void anyMethod() { … }
What does the override tag stand for ?
@Override - informs the compiler that the element is meant tooverride an element declared in a superclass.
@Override void overridingMethod() { }
If the method is not an overriding method, an error will be generated during compilation:
error: method does not override or implement a method from a supertype
What doe the predefined tag suppress warnings stand for ?
@SuppressWarnings - tells the compiler to suppress specific warnings.
@SuppressWarnings(”unchecked”)
@SuppressWarnings(”deprecation”)
@SuppressWarnings(“deprecation”)
_____void myMethod() {
________myObject.deprecatedMethod();
}