注解三种功能示例
//示例一:生成文档相关的注解
/**
* @description
* @Author: xiaoqiu
* @version 0.0.1
*/
class JavaDoc{
/**
* @Description:
* @Author: xiaoqiu
* @Date: 2021/9/1 16:49
* @param r:
* @return: double
* @Version: 0.0.1
*/
public static double getArea(int r){
double area = 3.14 * r * r;
return area;
}
}
//示例二:在编译时进行格式检查(JDK内置的三个基本注解)
class AnnotationTest{
public static void main(String[] args) {
@SuppressWarnings ( "unused" )
int a=10;
}
@Deprecated
public void print( ){
System.out.println( "过时的方法") ;
}
@Override
public String toString( ) {
return "重写的toString方法()";
}
}
//示例三:跟踪代码依赖性,实现替代配置文件功能
@WebServlet( "/login")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet (HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException { }
protected void doPost (HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}}