์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- git merge
- ํ๋ ์ ๊ตฌ์กฐ
- ์์๋ฒํธ
- leetcode
- ์ฝ๋ฉํ ์คํธ์ค๋น
- ํฐ์คํ ๋ฆฌ์ฑ๋ฆฐ์ง
- ์ค๋ธ์
- i-type
- 99ํด๋ฝ
- ์๋น์ค ํ๋ฆฌ๋ฏธํฐ๋ธ
- ์ค๋ฅ์ ์ด
- mariadb
- well known ํฌํธ
- til
- IEEE 802
- ๊ฐ๋ฐ์์ทจ์
- ๋ฐ์ดํฐ ์ ์ก
- reducible
- ํ ํฐ ๋ฒ์ค
- ํ๋ก์ด๋์์
- tcp ์ธ๊ทธ๋จผํธ
- ์ค๋ฅ๊ฒ์ถ
- xv6
- ํญํด99
- ์ฃผ๊ธฐ์ ํธ
- ๋น์ฃผ๊ธฐ์ ํธ
- tcp ํ๋กํ ์ฝ
- ๊ทธ๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ
- ์ค๋ ๋
- ์ฐ๋ถํฌdb
- Today
- Total
Unfazedโ๏ธ๐ฏ
๋ฉ์๋ ์ฐธ์กฐ(method reference) ๋ณธ๋ฌธ
๋ฉ์๋ ์ฐธ์กฐ
-ํ๋์ ๋ฉ์๋๋ง ํธ์ถํ๋ ๋๋ค์์ '๋ฉ์๋ ์ฐธ์กฐ'๋ก ๋ ๊ฐ๋จํ ํ ์ ์๋ค.
์ข ๋ฅ | ๋๋ค | ๋ฉ์๋ ์ฐธ์กฐ |
static๋ฉ์๋ ์ฐธ์กฐ | (x)-> ClassName.method(x) | ClassName::method |
์ธ์คํด์ค๋ฉ์๋ ์ฐธ์กฐ | (obj.x)->obj.method(x) | ClassName::method |
-static ๋ฉ์๋ ์ฐธ์กฐ
Integer method(String s) { //Integer.parseInt(String s)๋ง ํธ์ถ
return Integer.parseInt(s);
}
๋๋ค์
Function<String, Integer> f = (String s) -> Integer.parseInt(s);
๋ฉ์๋ ์ฐธ์กฐ
Function<string, integer> f = (String s) -> Integer::parseInt(s);
-์์ฑ์์ ๋ฉ์๋ ์ฐธ์กฐ
1)๋งค๊ฐ๋ณ์ ์๋ ๊ฒฝ์ฐ
๋๋ค์
Supplier<MyClass> s=()->new MyClass();
๋ฉ์๋ ์ฐธ์กฐ
Supplier<MyClass> s=MyClass::new;
2)๋งค๊ฐ๋ณ์ 1๊ฐ์ธ ๊ฒฝ์ฐ
๋๋ค์
Function<Integer, MyClass> s = (i) -> new MyClass(i);
๋ฉ์๋ ์ฐธ์กฐ
Function<Integer, MyClass> s= MyClass::new;
๋ฐฐ์ด๊ณผ ๋ฉ์๋ ์ฐธ์กฐ
๋๋ค์
Function<Integer, int[]> f = x->new int[x];
๋ฉ์๋ ์ฐธ์กฐ
Function<Integer, int[]> f2 = int[]::new; //๋ฐฐ์ดํ์ []::new
public class MethodReference {
public static void main(String[] args) {
Function<String,Integer> f=(String s) -> Integer.parseInt(s);
Function<String,Integer> f2=Integer::parseInt; //ํจ์ํ ์ธํฐํ์ด์ค์ ์ ๋ณด๊ฐ ์๊ธฐ ๋๋ฌธ์ ๋ฉ์๋์ฐธ์กฐ๊ฐ ๊ฐ๋ฅ
System.out.println(f.apply("100")+200);
System.out.println(f2.apply("100")+200);
Supplier<MyClass> s= ()->new MyClass();
Supplier<MyClass> s2= MyClass::new;
MyClass mc = s.get(); //MyClass ๊ฐ์ฒด ๋ฐํ
System.out.println(s.get());
MyClass mc2 = s2.get(); //MyClass ๊ฐ์ฒด ๋ฐํ
System.out.println(s2.get());
Function<Integer, MyClass2> f3=(i)->new MyClass2(i);
Function<Integer, MyClass2> f4=MyClass2::new;
MyClass2 mc3 = f3.apply(100);
System.out.println(mc3.iv);
System.out.println(f3.apply(200).iv);
MyClass2 mc4 = f4.apply(200);
System.out.println(mc4.iv);
Function<Integer, int[]> f5 = (i) -> new int[i];
System.out.println(f5.apply(100).length);
Function<Integer,int[]> f6 = int[]::new; //๋ฉ์๋ ์ฐธ์กฐ
System.out.println(f6.apply(200).length);
}
}
class MyClass{}
class MyClass2{
int iv;
MyClass2(int iv) {
this.iv=iv;
}
}
output:
300
300
java_study.MyClass@2a3046da
java_study.MyClass@2a098129
100
200
200
100
200
'Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Collection.toArray(new T[0]) vs .toArray(new T[size]) / ์ปฌ๋ ์ ์ ๋ฐฐ์ด๋ก ๋ณํํ๋ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ ์ฑ๋ฅ ๋น๊ต (0) | 2024.01.14 |
---|---|
๋ฌธ์์ด.repeat() ๋ฌธ์์ด ๋ฐ๋ณต ๋ฉ์๋ (java.lang.String) +๋ด๋ถ ์์ค์ฝ๋ ๋ถ์ (0) | 2023.10.27 |
์ปฌ๋ ์ ํ๋ ์์๊ณผ ํจ์ํ ์ธํฐํ์ด์ค (0) | 2023.10.06 |
Predicate์ ๊ฒฐํฉ (0) | 2023.10.06 |
java.util.function ํจํค์ง (0) | 2023.10.06 |