Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39961
| From | Knute Johnson <knute2023@585ranch.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Java 21 and [this-escape] warnings? |
| Date | 2023-06-09 20:32 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <u60jra$2275l$1@dont-email.me> (permalink) |
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. Please see the code
below and the script to compile it. I've commented out several lines
but you can un-comment them and see the warnings from the compiler. The
first one that I really don't understand is
Frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE). I would appreciate
any comments or maybe I just don't know what I'm doing and there is a
better way. If so please feel free to critique. It compiles and will
run but not work correctly with the lines commented out. Put them back
in and compile them to see the warnings.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class test extends JFrame {
private static final long serialVersionUID = 1L;
public test() {
super("test");
//setLayout(new GridBagLayout()); // [this-escape]
//setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //
[this-escape]
GridBagConstraints c = new GridBagConstraints();
JLabel l = new JLabel("this is a JLabel");
l.setBorder(new EmptyBorder(20,20,20,20)); // [this-escape]
sometimes
//add(l,c); // [this-escape]
//add(l); // [this-escape]
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
test t = new test();
t.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
t.dispose();
}
});
t.pack();
t.setVisible(true);
});
}
}
A script to compile the program above:
#!/bin/bash
if javac21 -Xlint:all -Xdiags:verbose -Xmaxerrs 10 -Xmaxwarns 10 test.java
then
jar cvfe test.jar test *.class
rm *.class
fi
javac21 is a link to the javac program from OpenJDK 21ea26. You can get
it here: https://jdk.java.net/21/
Thanks!
--
Knute Johnson
Back to comp.lang.java.programmer | Previous | Next — Next 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