Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39969
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java 21 and [this-escape] warnings? |
| Date | 2023-06-10 18:57 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <u62v4a$2ek0u$1@dont-email.me> (permalink) |
| References | <u60jra$2275l$1@dont-email.me> |
On 6/9/2023 9:32 PM, Knute Johnson wrote:
> I've been playing with Java21ea getting ready for its release this fall
> and have found some warnings that I don't really know how to deal with.
> I understand why you don't want 'this' escaping the constructor but I
> don't understand how Java21 think that a lot of the methods we have
> always used are going to cause that to happen.
I think the following example illustrates the problem
they are trying to solve.
public class ThisLeak {
public static class A {
protected boolean a;
public A() {
a = true;
}
public void m() {
System.out.printf("a=%b\n", a);
}
}
public static class B extends A {
protected boolean b1;
protected boolean b2;
public B() {
super();
b1 = true;
m();
b2 = true;
}
}
public static class C extends B {
private boolean c;
public C() {
c = true;
}
public void m() {
System.out.printf("a=%b b1=%b b2=%b c=%b\n", a, b1, b2, c);
}
}
public static void main(String[] args) {
new C();
}
}
And it also explains why final solve the problem.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Java 21 and [this-escape] warnings? Knute Johnson <knute2023@585ranch.com> - 2023-06-09 20:32 -0500
Re: Java 21 and [this-escape] warnings? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2023-06-10 13:46 +0200
Re: Java 21 and [this-escape] warnings? Knute Johnson <knute2023@585ranch.com> - 2023-06-10 13:23 -0500
Re: Java 21 and [this-escape] warnings? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2023-06-11 14:45 +0200
Re: Java 21 and [this-escape] warnings? Eric Sosman <donalhambra@gmail.com> - 2023-06-10 06:58 -0700
Re: Java 21 and [this-escape] warnings? Knute Johnson <knute2023@585ranch.com> - 2023-06-10 13:26 -0500
Re: Java 21 and [this-escape] warnings? Arne Vajhøj <arne@vajhoej.dk> - 2023-06-10 18:57 -0400
csiph-web