Created
October 1, 2021 17:00
-
-
Save pysoftware/125db7ec5b61095919ecef4f7bc93197 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
T t = new T(); | |
C c = new C(); | |
c.a = "a"; | |
C c1 = new C(); | |
c1.a = "b"; | |
t.a.addAll(List.of(c, c1)); | |
Finder finder = new Finder(t); | |
C finded = finder.find("a"); | |
// finded.a = "C"; | |
check(finded); | |
System.out.println(t.a); | |
} | |
static void check(C findede) { | |
findede.a = "C"; | |
} | |
static class Finder { | |
private final T t; | |
Finder(T t) { | |
this.t = t; | |
} | |
C find(String c) { | |
return t.a.stream().filter(cc -> c.equals(cc.a)).findFirst().get(); | |
} | |
} | |
static class C { | |
public String a; | |
@Override | |
public String toString() { | |
return "C{" + | |
"a='" + a + '\'' + | |
'}'; | |
} | |
} | |
static class T { | |
public List<C> a = new ArrayList<>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment