develog

[Java] template callback return value 본문

Dev/Java

[Java] template callback return value

냐옴 2014. 10. 1. 11:18

TestMain2

public class TestMain2 {

    public static void main(String[] args) {

   

        TestMain2 main = new TestMain2();

        

        Object ret = main.template(new TestJob() {

        public Object doJob(int num1, int num2) {

        return num1 + num2;

        }

        }, 11, 22);

        

        System.out.println("ret : " + ret);

        

    }

    

    private Object template(TestJob job, int num1, int num2) {

    Object ret = null;

try {

ret = job.doJob(num1, num2);

} catch (Exception e) {

System.out.println("catch, " + e.getMessage());

} finally {

}

return ret;

}

    

}


TestJob

interface TestJob {

    public Object doJob(int num1, int num2);

}



'Dev > Java' 카테고리의 다른 글

[Java] @Transactional, tx:advice MIX  (0) 2014.10.07
[Java] Generics  (0) 2014.10.06
[Java] 톰캣 설치 폴더 찾기  (0) 2014.09.24
[Java] Java IO  (0) 2014.09.22
[Java] removeTag  (0) 2014.09.18
Comments