Is there a way to take an argument in a callable method?

后端 未结 7 1060
Happy的楠姐
Happy的楠姐 2020-12-23 16:41

I have created a piece of code which takes an IP address (from main method in another class) and then loops through a range of IP addresses pinging each one as it goes. I ha

7条回答
  •  借酒劲吻你
    2020-12-23 17:09

    Adding to Jarle's answer -- in case you create Callable as instance of anonymous class, you can use final field outside of anonymous class for passing data into the instance:

        final int arg = 64;
        executor.submit(new Callable() {
            public Integer call() throws Exception {
                return arg * 2;
            }
        });
    

提交回复
热议问题