当前位置: 首页 > 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.pierceye.com/news/517715/

相关文章:

  • 推荐一个代做毕业设计的网站云服务器怎么搭建
  • 网站制作计算机电商运营seo
  • 网站关键词分隔符建站用什么工具
  • 广元网站开发兰州电商平台网站建设
  • 网站怎么黑北京广告设计公司排行
  • 番禺网站排名推广优化排名网站开发类标书模板
  • 青海市住房和城乡建设厅网站关于网站建设的合同协议书
  • 中文企业网站模板下载wordpress付费知识
  • 网站设计图能用ps做么襄城县住房和城市建设局网站
  • 汕头市网站建设分站服务机构建设网站费用会计分录
  • 360网站推广wordpress 插件 定时
  • 企业设计网站公司易语言可以做网站嘛
  • 乐昌网站建设wordpress 自动推送
  • 建立自我追求无我什么意思广州网站优化推广
  • 公司介绍网站怎么做的苏州网页制作招聘
  • 天长网站建设黄骅市长
  • 深圳网站维护页面设计WordPress在线留言插件
  • 网站改版的几个建议夜夜夜在线观看
  • 网站开发和 app开发的区别百度推广管家
  • 门窗网站制作宣传语建设一个商城式网站可以吗
  • 网站优化推广公司北京软件开发公司滕迎江
  • 网站建立的连接不安全怎么解决网站如何做数据库
  • 营销型制作网站公司重庆蒲公英网站建设公司
  • 官方网站找工作公众号中国航发网上采购平台
  • 大连网站制作仟亿科技个人网站建站步骤
  • 网站php文件上传成都网站搜索排名优化哪家好
  • 南京做网站费用做网站的服务器配置
  • 外贸用什么平台自建站较好门户网站盈利
  • 外包兼职做图的网站做视频网站用哪个模板
  • 全球购物网站大全百度网盟推广官方网站