JAVA callback function [類似 C# .NET anonymous delegate(委託)]
JAVA callback function [類似 C# .NET anonymous delegate(委託)]
資料來源: https://stackoverflow.com/questions/443708/callback-functions-in-java
https://www.javatpoint.com/java-callback-function
Code
public class Main { public interface Visitor{ int doJob(int a, int b); } public static void main(String[] args) { Visitor adder = new Visitor(){ public int doJob(int a, int b) { return a + b; } }; Visitor multiplier = new Visitor(){ public int doJob(int a, int b) { return a*b; } }; System.out.println(adder.doJob(10, 20)); System.out.println(multiplier.doJob(10, 20)); } }
One thought on “JAVA callback function [類似 C# .NET anonymous delegate(委託)]”
C/C++ callback function 函數指標 類似