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

网站登录页面模板下载西安做网站费用

网站登录页面模板下载,西安做网站费用,军事最新消息今天,齐家网和土巴兔装修哪家好Java基础之注解 一、Java注解1.1、内置注解1.2、元注解1.3、自定义注解 一、Java注解 注解#xff08;Annotation#xff09;是一种为程序代码提供元数据#xff08;metadata#xff09;的方式。注解提供了关于程序代码的额外信息#xff0c;这些信息可以在运行时或编译时… Java基础之注解 一、Java注解1.1、内置注解1.2、元注解1.3、自定义注解 一、Java注解 注解Annotation是一种为程序代码提供元数据metadata的方式。注解提供了关于程序代码的额外信息这些信息可以在运行时或编译时被读取并处理。Java 的注解以 符号开头例如 Override、Deprecated 等。 1.1、内置注解 Override 表示该方法覆盖了父类的方法。通常用于帮助编译器检查是否正确地覆盖了父类的方法。 Deprecated 表示该方法或类已经过时不推荐使用。编译器在使用过时的方法或类时会发出警告。 SuppressWarnings 抑制编译器警告。可以用于特定的方法或整个类。 class Parent {public void printMessage() {System.out.println(Parent class);} }class Child extends Parent {Overridepublic void printMessage() {System.out.println(Child class);} }class DeprecatedExample {Deprecatedpublic void oldMethod() {System.out.println(This method is deprecated.);} }class SuppressWarningExample {SuppressWarnings(unchecked)public void uncheckedOperation() {// 一些操作} }public class AnnotationExample {public static void main(String[] args) {// 使用 Override 注解Parent parent new Child();parent.printMessage(); // 输出 Child class// 使用 Deprecated 注解DeprecatedExample example new DeprecatedExample();example.oldMethod(); // 输出 This method is deprecated.// 使用 SuppressWarnings 注解SuppressWarningExample suppressWarningExample new SuppressWarningExample();suppressWarningExample.uncheckedOperation(); // 不会产生未经检查的警告} }1.2、元注解 元注解是应用于其他注解的注解用于控制注解的行为。 Retention 指定注解的保留策略即注解在何时可用。有 RetentionPolicy.SOURCE、RetentionPolicy.CLASS 和 RetentionPolicy.RUNTIME 三种策略。Target 指定注解可以应用于的元素类型如类、方法、字段等。Documented 表示注解将包含在 JavaDoc 文档中。 import java.lang.annotation.*;Retention(RetentionPolicy.RUNTIME) Target({ElementType.METHOD, ElementType.TYPE}) Documented Inherited public interface MyCustomAnnotation {String value() default default value;int count() default 0; }MyCustomAnnotation(value Custom Value, count 42) class AnnotatedClass {MyCustomAnnotation(value Custom Method)public void annotatedMethod() {// 方法实现} }public class AnnotationIntegrationExample {public static void main(String[] args) {// 获取类级别的注解信息MyCustomAnnotation classAnnotation AnnotatedClass.class.getAnnotation(MyCustomAnnotation.class);System.out.println(Class Annotation Value: classAnnotation.value());System.out.println(Class Annotation Count: classAnnotation.count());// 获取方法级别的注解信息try {AnnotatedClass annotatedInstance new AnnotatedClass();MyCustomAnnotation methodAnnotation annotatedInstance.getClass().getMethod(annotatedMethod).getAnnotation(MyCustomAnnotation.class);System.out.println(Method Annotation Value: methodAnnotation.value());System.out.println(Method Annotation Count: methodAnnotation.count());} catch (NoSuchMethodException e) {e.printStackTrace();}} }1.3、自定义注解 自定义注解的定义方式类似于接口但使用 interface 关键字。 interface用来声明一个注解格式public interface注解名{定义内容}其中的每一个方法实际上是声明了一个配置参数方法的名称就是参数的名称返回值类型就是参数的类型返回值只能是基本类型 Class, String,enum可以通过 defau来声明参数的默认值如果只有一个参数成员一般参数名为vaue注解元素必须要有值我们定义注解元素时经常使用空字符串0作为默认值 import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;// 定义自定义注解 Retention(RetentionPolicy.RUNTIME) Target({ElementType.TYPE, ElementType.METHOD}) public interface MyCustomAnnotation {String value() default default value;int count() default 0; }// 使用自定义注解 MyCustomAnnotation(value Custom Class, count 10) public class AnnotatedClass {MyCustomAnnotation(value Custom Method, count 5)public void annotatedMethod() {// 方法实现} }public class CustomAnnotationExample {public static void main(String[] args) {// 获取类级别的注解信息MyCustomAnnotation classAnnotation AnnotatedClass.class.getAnnotation(MyCustomAnnotation.class);System.out.println(Class Annotation Value: classAnnotation.value());System.out.println(Class Annotation Count: classAnnotation.count());// 获取方法级别的注解信息try {AnnotatedClass annotatedInstance new AnnotatedClass();MyCustomAnnotation methodAnnotation annotatedInstance.getClass().getMethod(annotatedMethod).getAnnotation(MyCustomAnnotation.class);System.out.println(Method Annotation Value: methodAnnotation.value());System.out.println(Method Annotation Count: methodAnnotation.count());} catch (NoSuchMethodException e) {e.printStackTrace();}} }
http://www.zqtcl.cn/news/517715/

相关文章:

  • 网站建设什么是静态网页设置wordpress文章标题高亮的代码
  • 男女做那事是什 网站wordpress怎么上传ppt
  • 电商网站图片处理东莞网络营销策划
  • 做知识产权相关的网站网站怎么做登录界面
  • 网站空间备份东莞企业网站教程
  • 新桥企业网站建设有关网站建设的毕业设计
  • 中山网站建设工作修改wordpress后台地址
  • 西安app网站开发如何制作一个自己的网页
  • 陇西学做网站鄂州网约车
  • 做类似58类型网站免费源码分享
  • 个人做的网站有什么危险网站模板怎样发布
  • 设计建设网站公司网站wordpress k2
  • 公司网站被抄袭网络宣传
  • 企业网站设计收费专业网络推广公司排名
  • 视频网站模板源码深圳网站建设明细报价表
  • nike官方网站定制二级域名网站有哪些
  • 越秀移动网站建设房门户网站如何做优化
  • 什么软件可以做动漫视频网站开发一个小程序大概要多少钱
  • 微网站可以做成域名访问株洲网站做的好的公司
  • 建设网站去工信部备案需要什么资料网站建设相关博客
  • 十度网站建设网站建立的企业
  • 婚庆公司网站国外网站阻止国内访问怎么做
  • 乐山高端网站建设wordpress openload
  • 哪些网站上可以做租车深圳品牌网站开发
  • 乐清网站改版公司西安网站建设公司哪家好
  • 国外小型网站1688货源网下载
  • 浏览量最大的网站网站导航栏目设计内容依据
  • 户外拓展公司网站开发桂林网站开发
  • 怎么入侵网站后台互联网营销师含金量
  • 网站建设ningqueseo济南网站建设服务