Skip to content

Instantly share code, notes, and snippets.

@pysoftware
Created October 1, 2021 17:00
Show Gist options
  • Save pysoftware/125db7ec5b61095919ecef4f7bc93197 to your computer and use it in GitHub Desktop.
Save pysoftware/125db7ec5b61095919ecef4f7bc93197 to your computer and use it in GitHub Desktop.
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