怎么查公司信息免费seo快速排名工具

当前位置: 首页 > news >正文

怎么查公司信息,免费seo快速排名工具,营销推广的形式包括,.net做网站安全吗注解/元数据#xff08;Annotation#xff09;#xff0c;是对代码级别的说明#xff1b;在JDK1.5及以后版本引入的一个特性#xff0c;与类、接口、枚举是在同一个层次。可以声明在包、类、字段、方法、局部变量、方法参数等的前面#xff0c;用来对这些元素进行说明、注…注解/元数据Annotation是对代码级别的说明在JDK1.5及以后版本引入的一个特性与类、接口、枚举是在同一个层次。可以声明在包、类、字段、方法、局部变量、方法参数等的前面用来对这些元素进行说明、注释主要可以用于创建文档跟踪代码中的依赖性执行基本编译时检查注解是以‘注解名’在代码中存在的根据注解参数的个数我们可以将注解分为标记注解、单值注解、完整注解三类它们都不会直接影响到程序的语义只是作为标识存在可以通过反射机制实现对这些元数据用来描述数据的数据的访问并且可以在编译时选择代码里的注解是否只存在于源码级或者也能在class文件、或者运行时中出现SOURCE/CLASS/RUNTIME。 一、按照作用Annotation有三种作用 1、编写文档文档注解通过代码里标识的注解生成文档【生成doc文档通过 javadoc 类文件名称 的方式生成对应的html文档文档中会将文档注解进行解析生成内容】 编写类文件并使用文档注解进行标注 使用 javadoc 类文件名称 进行生成文档这一步可能会报错 错误: 编码GBK的不可映射字符 原因是 java程序在编译的时候需要使用JDK开发工具包中的JAVAC.EXE命令默认编码格式为UNICODE而我们的代码并非这个编码格式解决方案是比如使用 notepad 编写Java代码前先将Java文件的编码格式改为 ANSI编码格式 然后编写代码并保存重新执行javadoc即可如果没有报错但生成的文档打开中文乱码也可以采用该方法解决 打开 index.html 文件如下 2、代码分析功能注解通过代码里标识的注解对代码进行分析【使用反射实现该功能最重要的功能】 3、编译检查编译验证注解通过代码里标识的注解让编译器能够实现基本的编译检查【如Override表示这个方法是对父类方法的重写如果被Override注解标记的方法父类不存在该方法那么编译无法通过、编码软件也会提示错误】
二、Java常见内置注解 1、Override作用是对覆盖超类中方法的方法进行标记如果被标记的方法并没有实际覆盖超类中的方法则编译器会发出错误警告。 2、Deprecated作用是对不应该再使用的方法进行标记标记方法过时比如有新版本的方法之后不建议使用以前版本的方法使用这些方法时将会在编译时显示提示信息这些过时方法也是可以正常使用的只是被提示标记而已与javadoc里的deprecated注解的功能相同但 javadoc deprecated 可以支持参数。 3、SuppressWarnings作用是压制警告可选值有以下几种写哪种值就代表压制哪种类型的警告 deprecation使用了过时的类或方法时的警告即被Deprecated标记的类或方法 unchecked执行了未检查的转换时的警告如使用集合时没有用泛型 (Generics) 来指定集合保存的类型 fallthrough当 switch 程序块直接通往下一种情况而没有 break 时的警告 path在类路径、源文件路径等中有不存在的路径时的警告 serial当在可序列化的类上缺少serialVersionUID 定义时的警告 finally 任何 finally 子句不能正常完成时的警告 rawtypes泛型类型未指明 unused 引用定义了但是没有被使用 all关于以上所有情况的警告
三、元注解 元注解的作用就是负责注解其他注解Java定义了4个标准的meta-annotation类型他们被用来提供对其他annotation类型作说明 这些类型和它们所支持的类在java.langannotation包中可以找到(TargetRetentionDocumentedInherited )。 Target用于描述注解的使用范围(即:Target元注解用来设置注解可以用在什么地方)经常使用最主要的就三个TYPE、METHOD、FIELD package java.lang.annotation;/*** The constants of this enumerated type provide a simple classification of the* syntactic locations where annotations may appear in a Java program. These* constants are used in {link Target java.lang.annotation.Target}* meta-annotations to specify where it is legal to write annotations of a* given type.** pThe syntactic locations where annotations may appear are split into* emdeclaration contexts/em , where annotations apply to declarations, and* emtype contexts/em , where annotations apply to types used in* declarations and expressions.** pThe constants {link #ANNOTATION_TYPE} , {link #CONSTRUCTOR} , {link* #FIELD} , {link #LOCAL_VARIABLE} , {link #METHOD} , {link #PACKAGE} ,* {link #PARAMETER} , {link #TYPE} , and {link #TYPE_PARAMETER} correspond* to the declaration contexts in JLS 9.6.4.1.** pFor example, an annotation whose type is meta-annotated with* {code Target(ElementType.FIELD)} may only be written as a modifier for a* field declaration.** pThe constant {link #TYPE_USE} corresponds to the 15 type contexts in JLS* 4.11, as well as to two declaration contexts: type declarations (including* annotation type declarations) and type parameter declarations.** pFor example, an annotation whose type is meta-annotated with* {code Target(ElementType.TYPE_USE)} may be written on the type of a field* (or within the type of the field, if it is a nested, parameterized, or array* type), and may also appear as a modifier for, say, a class declaration.** pThe {code TYPE_USE} constant includes type declarations and type* parameter declarations as a convenience for designers of type checkers which* give semantics to annotation types. For example, if the annotation type* {code NonNull} is meta-annotated with* {code Target(ElementType.TYPE_USE)}, then {code NonNull}* {code class C {…}} could be treated by a type checker as indicating that* all variables of class {code C} are non-null, while still allowing* variables of other classes to be non-null or not non-null based on whether* {code NonNull} appears at the variables declaration.** author Joshua Bloch* since 1.5* jls 9.6.4.1 Target* jls 4.1 The Kinds of Types and Values/ public enum ElementType {/** Class, interface (including annotation type), or enum declaration 类, 接口 (包括注释类型), 或 枚举 声明/TYPE,/** Field declaration (includes enum constants) 字段声明包括枚举常量/FIELD,/** Method declaration 方法声明(Method declaration)/METHOD,/** Formal parameter declaration 正式的参数声明/PARAMETER,/** Constructor declaration 构造函数声明/CONSTRUCTOR,/** Local variable declaration 局部变量声明/LOCAL_VARIABLE,/** Annotation type declaration 注解类型声明/ANNOTATION_TYPE,/** Package declaration 包声明/PACKAGE,/** Type parameter declaration 类型参数声明** since 1.8/TYPE_PARAMETER,/** Use of a type 使用的类型** since 1.8/TYPE_USE }Retention表示需要在什么级别保存该注解信息用于描述注解的生命周期 (可选值SOURCE CLASS RUNTIME) Documented说明该注解将被包含在javadoc中即注解是否被抽取到api文档中使用 javadoc 类文件名称 命令生成文档时将该注解是否保留在文档中 Inherited说明子类可以继承父类中使用的被Inherited注解标记的注解比如A类是B类的父类如果在A类上使用被Inherited元注解声明的注解那么B类也会继承该注解会自动加上该注解 四、自定义注解 1、格式 元注解 public interface 注解名称{ 注解属性列表即接口中的抽象方法 } package com.database.pool.testpool.annotation;import java.lang.annotation.;/*** 测试注解1/ Target(value ElementType.TYPE) //元注解定义当前注解可使用范围 Retention(value RetentionPolicy.RUNTIME) //元注解定义当前注解生命周期 Inherited //元注解定义子类可以继承父类中使用的该注解 public interface Test1Annotation {//属性String value(); }2、本质 注解本质上就是一个接口该接口默认继承Annotation接口 public interface Test1Annotation extends java.lang.annotation.Annotation {} 3、注解属性说明 : 接口中的抽象方法 a、属性抽象方法返回值要求只能是以下几种类型 八大基本数据类型String枚举注解以上四种类型的数组 b、使用注解时需要给属性赋值要求如下 定义了属性使用时就必须给属性赋值格式注解名(属性名1属性值1,属性名2属性值2)。如果定义属性时使用default关键字给属性默认初始化值则使用注解时可以不进行该属性的赋值会自动使用默认值。使用注解时如果只有一个属性需要赋值并且属性的名称是value则value可以省略直接定义值即可也就是说注解只有一个value名称的属性或注解有多个属性但这些属性都有默认值所以使用时只需要对value属性赋值的话也可以直接写值。数组属性赋值时值使用{}包裹属性值如果数组中只有一个值则{}省略直接写值。 建议注解如果只有一个属性那么将该属性名定义为value。 示例 自定义注解 package com.database.pool.testpool.annotation;import com.database.pool.testpool.User;import java.lang.annotation.;/*** 测试注解1/ Target(value ElementType.TYPE) //元注解定义当前注解可使用范围 Retention(value RetentionPolicy.RUNTIME) //元注解定义当前注解生命周期 Inherited //元注解定义子类可以继承父类中的该注解子类可以继承父类使用的注解 public interface Test1Annotation {/** 属性抽象方法定义* return/int paramInt();//default 标记属性默认值使用注解时该属性如果不做更改使用默认值时可以不设置该属性的值String paramStr() default c;//返回类型是另一个注解类型Test1Annotation2 paramAnn();//返回类型是枚举User paramUser();String[] paramStrArr();//value名称的属性在使用注解时如果只有value属性设置值则可以省略属性名value直接写值String value(); }测试注解2 package com.database.pool.testpool.annotation;import java.lang.annotation.;/*** 测试注解2用于给测试注解1的属性设置返回值为注解类型/ Target(value ElementType.TYPE) Retention(value RetentionPolicy.RUNTIME) Inherited public interface Test1Annotation2 { }枚举 package com.database.pool.testpool;/** 定义枚举用于设置测试注解1的属性返回值为枚举类型/ public enum User {U1,U2;}使用注解 package com.database.pool.testpool;import com.database.pool.testpool.annotation.Test1Annotation; import com.database.pool.testpool.annotation.Test1Annotation2;/** 测试注解1使用类/ Test1Annotation(paramInt 1,paramAnn Test1Annotation2,paramStrArr {a,b},paramUser User.U1,value x) public class TestAnn { } 解析注解 package com.database.pool.testpool;import com.database.pool.testpool.annotation.Test1Annotation;/** 反射解析自定义注解—测试注解1*/ public class Test {public static void main(String[] args) {//获取Class对象ClassTestAnn aClass TestAnn.class;//获取类级别的Test1Annotation类型的注解实际上返回值是一个实现了Test1Annotation注解接口的类的对象里面有获取各个属性的值的方法Test1Annotation annotation aClass.getAnnotation(Test1Annotation.class);//拿到注解信息后就可以根据注解信息做各种操作int i annotation.paramInt();System.out.println(paramInti);String s annotation.paramStr();System.out.println(paramStrs);String value annotation.value();System.out.println(valuevalue);}}总结 1、程序开发中大部分时候是使用注解而不是自定义注解 2、注解给谁用 ? 编译器编译器识别注解给解析程序用解析程序通过解析注解实现自定义功能 3、注解不是程序的一部分相当于是给程序做了一个标记然后通过反射机制实现注解功能对程序原有功能做增强等 Java反射 Java泛型