Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with figuring out this statement in Java terms  RSS feed

 
Bill Hoke
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Form1 extends JFrame implements ActionListener {
...
public Form1() {
...
public static void main(String args[]) {
...
(new Form1()).setVisible(true);

What does the above line mean in Java terms please.


Thank you very much!
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just the last line? Well, new Form1() creates a new Form1 object. So that statement creates a new Form1 object, and then immediately calls its setVisible method.

You could also write it as:That's what you'd do if you needed to keep a reference to the form. If you don't, then you can do it all in one line, if you want.
 
Bill Hoke
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for your quick response.
That solved this issue. Thanks again.
 
Rob Spoor
Sheriff
Posts: 21087
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the new operator has a higher precedence than the . operator you can omit the parentheses:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!