-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvJava_Ch19_20_Annotations.java
More file actions
66 lines (52 loc) · 2.37 KB
/
AdvJava_Ch19_20_Annotations.java
File metadata and controls
66 lines (52 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package AdvancedJava;
class Information{
java.util.Scanner input = new java.util.Scanner(System.in);
void RollNo(){
System.out.print("Enter Your Admission No. ");
String admNo = input.nextLine();
}
}
class ExtendedInformation extends Information{
@Override // Usage of Override method
void RollNo(){
super.RollNo();
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Enter Your Class Roll No: ");
String rollNo = input.nextLine();
}
@Deprecated //Usage of Deprecated Annotation
void Initials(){
java.util.Scanner input = new java.util.Scanner(System.in);
System.out.print("Write Name Initials: ");
String initials = input.next();
}
}
@FunctionalInterface //Usage of FunctionalInterface annotation
interface makingOfFunctionalInterface{
void FI();
// Note if any other method is added to this interface, it would not be a functional interface
}
public class AdvJava_Ch19_20_Annotations {
// NOTES:
/* Annotations-
~ These provide extra information about the code blocks which we have written.
~ It provides metadata to class/methods.
~It can sometimes also save from errors
Ex. We want to override a method, and we put annotation there but upon overriding we mistakenly
write wrong method_name then the method will not be overridden, hence the Annotation will
show up an error. And prevents from runtime errors.
Some annotations are:
1. @Override: It is used to mark overridden methods in a block of code. [Line 12]
2. @SuppressWarnings - It is used to suppress the warnings which are generated by the compiler.
Syntax:
@SuppressWarnings("Warning_Name");
3. @Deprecated - If you want to deprecate a method, it is used. [Line 20]
4. @FunctionalInterface - Marks functional interface being made in a code.
Functional interface are interfaces with only a single method, and it must be abstract method. */
@SuppressWarnings( "deprecation" )
public static void main(String[] args) {
ExtendedInformation myInfo = new ExtendedInformation();
myInfo.RollNo();
myInfo.Initials(); // Deprecated method usage [compiler shows but not in code due to, @SuppressWarnings annotation in line 46
}
}