zoukankan      html  css  js  c++  java
  • JAVA重写不需要@override

    一,如下代码,

    package com.boot.enable.bootenable;
    
    import org.springframework.scheduling.annotation.Async;
    import org.springframework.stereotype.Component;
    
    import java.util.concurrent.TimeUnit;
    
    @Component("RunnableDemo")
    public class RunnableDemo implements Runnable {
        @Override
        @Async // 异步方式执行方法
        public void run() {
            for(int i=0;i<5;i++)
            {
                System.out.println(i);
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    package com.boot.enable.bootenable;
    
    import org.springframework.stereotype.Component;
    
    @Component("RunnableDemo2")
    public class RunnableDemo2 implements Runnable {
        public void run() {
            for (int i=6;i<10;i++)
            {
                System.out.println(i);
            }
        }
    }
    package com.boot.enable.bootenable;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.ConfigurableApplicationContext;
    
    @SpringBootApplication
    public class BootEnableApplication {
        public static void main(String[] arg) {
            ConfigurableApplicationContext context = SpringApplication.run(BootEnableApplication.class);
            Runnable bean = context.getBean("RunnableDemo", Runnable.class);
            System.out.println("start");
            bean.run();
            System.out.println("end");
        }
    }

    二,可以运行,不写JAVA重写不需要@override,编译也是通过的,那个是注解,是给编译器看的,告诉编译器我下面写的代码是重写方法,让编译器检查,执行的时候不会执行注解代码

  • 相关阅读:
    [转]BIOS中断汇编函数---留用
    SWT/JFace 按键、事件、监听
    erlang局域网内通信
    ios热修复
    swift里面!和?的作用
    AFNetworking上传下载图片
    横向滚动的UITableView
    判断iphone手机型号
    iPhone屏幕尺寸、分辨率及适配
    UITapGestureRecognizer 和UIPanGestureRecognizer的使用,触摸和滑动
  • 原文地址:https://www.cnblogs.com/May-day/p/11847985.html
Copyright © 2011-2022 走看看