How to start anonymous thread class

前端 未结 8 760
清歌不尽
清歌不尽 2020-12-04 15:37

I have the following code snippet:

public class A {
    public static void main(String[] arg) {
        new Thread() {
            public void run() {
               


        
8条回答
  •  长情又很酷
    2020-12-04 15:57

    Add: now you can use lambda to simplify your syntax. Requirement: Java 8+

    public class A {
        public static void main(String[] arg)
        {
            Thread th = new Thread(() -> {System.out.println("blah");});
            th.start();
        }
    }
    

提交回复
热议问题