有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在下面的多线程程序中出错

下面的java代码显示了编译错误,请告诉我如何克服这些错误

    public class Chaining {

    import java.util.concurrent.CompletableFuture;

    public class Chaining {

        public static void main(String[] args) {
              CompletableFuture.supplyAsync(() -> ThreadLocalRandom.current().nextInt(1, 10))// ** getting compilation error ***
                               .thenApply(Math::sqrt)
                               .thenAccept(System.out::println)
                               .join();
          }

}
}

共 (1) 个答案

  1. # 1 楼答案

    应该是这样的:

    import java.util.concurrent.CompletableFuture;
    import java.util.concurrent.ThreadLocalRandom;
    
    public class Chaining {
    
        public static void main(String[] args) {
            CompletableFuture.supplyAsync(() -> ThreadLocalRandom.current().nextInt(1, 10))// ** getting compilation error ***
                    .thenApply(Math::sqrt)
                    .thenAccept(System.out::println)
                    .join();
        }
    
    }
    

    请学习使用IDE的功能