To mark a method as deprecated we can use the JavaDoc @deprecated
tag. This is what we did since the beginning of Java. But when a new metadata support introduced to the Java language we can also use annotation. The annotation for marking method as deprecated is @Depreated
.
The difference between these two that the @deprecated
is place in the JavaDoc comment block while the @Deprecated
is placed as a source code element.
package org.kodejava.basic;
import java.util.Date;
import java.util.Calendar;
public class DeprecatedExample {
public static void main(String[] args) {
DeprecatedExample de = new DeprecatedExample();
de.getDate();
System.out.println(de.getMonthFromDate());
}
/**
* Get current system date.
*
* @return current system date.
* @deprecated This method will be removed in the near future.
*/
@Deprecated
public Date getDate() {
return new Date();
}
public int getMonthFromDate() {
return Calendar.getInstance().get(Calendar.MONTH);
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024