Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 행열. 2중반복문..
- while문이 틀린이유?? math.random()을 사용해서푸는법?
- (참고로 boolean 배열의 default 값은 false 이다.
- form.getImageFies 오타났음
- 마지막에 배열의 foreach구문이 틀린것같은데 ...... 저게왜틀린건지나는잘모르겠슴다.
- 그럼 int배열의 deefault값은?????
- ㅓㅂ
- 출처:구멍가게코딩단-코배스(개정판)
- boolean배열
- 생활코딩
- bindingresult 쓰니까 에러났다. 어떻게해야하냐;;
Archives
- Today
- Total
푸린세스
생성자의 메서드 참조. 본문
package ex14;
import java.util.function.Function;
import java.util.function.Supplier;
public class Ex14_04 {
public static void main(String[] args) {
//Supplier는 입력x, 출력o
// Supplier<MyClass> s = () -> new MyClass();
// MyClass mc = s.get(); //supplier로부터 get하면 MyClass객체반환
// System.out.println(mc); //객체를 출력
//// 밑에 한문장이로 줄인것.
// System.out.println(s.get());
// System.out.println(mc); //헤시코드 다름, 또다른 객체가 만들어진것.
//supplier의 메소드?? get()이다....
//매서드 참조로 바꾸기.
// Supplier<MyClass> s = 클래스이름::메서드이름;
// Supplier<MyClass> s2 = MyClass::new;
// System.out.println(s2.get());
//
Function<Integer, MyClass> f = (i)->new MyClass(i);
Function<Integer, MyClass> f2 = MyClass::new;
MyClass mc2 = f.apply(100);
System.out.println(mc2);
System.out.println(mc2.iv);
System.out.println(f.apply(100).iv);
//Function에 쓰는 메소드는 apply적용하는것
// Function<Integer, int[]> f3 = (i) -> new int[i];
// Function<Integer, int[]> f3 = 클래스이름::메서드이름;
Function<Integer, int[]> f3 = int[]::new;
int[]arr = f3.apply(100);
System.out.println("arr.length=" + arr.length);
System.out.println(f3.apply(100).length);
}
}
class MyClass{
int iv;
MyClass(int iv){
this.iv = iv;
}
}