글

라벨이 람다식인 게시물 표시

[Java] 인터페이스 람다식으로 구현하기

//람다식으로 인터페이스 구현하기 public class Pg36_lambda { public static void main(String[] args) { Showable s; Utils u = new Utils(); Operable o; Pickable p; IntArray i; Newable n; s = str -> System.out.println(str); o = (x,y) -> u.add(x, y); p = (x,y) -> x.charAt(y); n = x -> new String(x); i = x -> new int[x]; s.show("잘있어"); o.operator(20, 30); p.pick("여보세요", 2); n.getString("사과"); int[] arr = i.getArray(2); arr[0] = 0; arr[1] = 1; } } interface Showable{ void show(String s); } interface Pickable{ char pick(String s1, int i); } interface Operable{ int operator(int x, int y); } interface Newable{ String getString(String s); } interface IntArray{ int[] getArray(int size); } class Utils{ int add(int a, int b) { return a+b; } } ============================Manual ============================ 인터페이스를 구현하는 방법 중 람다식으로 구현하는 방법이 있다. 람다식은 y = f(x) 방식으로 작성된다. f(x) -> y 라고 볼 수 있는데  (x,y) ...