zoukankan      html  css  js  c++  java
  • new Runnable中的 this

    package com.test;
    
    public class BB extends AA{
        
        public String bb = "bbbbb";
        public void gg() {
            System.out.println("bbgg");
        }
        public void gg1() {
            System.out.println("aagg");
        }
    }
    package com.test;
    
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    
    public abstract class AA extends CC{
        int d = 111;
        
        public void gg() {
            System.out.println("aagg");
        }
        public abstract  void gg1();
        
        public void ff() {
            ExecutorService pool = Executors.newCachedThreadPool();
              for(int i = 1; i < 2;i++){
                  pool.execute(new Runnable() {
                      Thread thread = Thread.currentThread();
                      public int ss = 2;
                      public void gg() {
                          System.out.println("Runnable gg");
                      }
                      
                    @Override
                    public void run() {
                        AA.this.gg();// this = com.test.AA$1。    里面有属性ss = 2,this$0 = com.test.BB。      调用的BB的gg()
                        AA.this.gg1();//   调用的BB的gg1()
                    } 
                }); 
              } 
              pool.shutdown();
        };
        public static void main(String[] args) {   
            BB x = new BB();
            x.ff();
        }
    }
    package com.test;
    
    public class CC {
        String ss = "ppp";
        
        private void gg1() {
            System.out.println("sssgg1");
        }
        private void gg() {
            System.out.println("sssgg");
        }
    }
  • 相关阅读:
    洛谷 P2678 跳石头
    洛谷 P1145 约瑟夫
    LibreOJ #515. 「LibreOJ β Round #2」贪心只能过样例
    洛谷 P2966 [USACO09DEC]牛收费路径Cow Toll Paths
    网络编程 --- TCP
    进程
    并发编程
    网络编程 --- UDP
    网络编程
    面向对象编程 --- 反射
  • 原文地址:https://www.cnblogs.com/yaowen/p/9364204.html
Copyright © 2011-2022 走看看