java8特性表达式

 public static void main(String[] args) {
        JFrame jframe = new JFrame("My JFrame");
        JButton jButton = new JButton("My JButton");
///表达式写法:如果有多行就加中括号,一行不用加
        jButton.addActionListener(event -> {
            System.out.println("Button Pressed!");
            System.out.println("hello world");
            System.out.println("executed");
        });

        jframe.add(jButton);
        jframe.pack();
        jframe.setVisible(true);
        jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    /**
     *lambda表达式基本结构:
     *{param1,param2,param3}->{}
     *
     *
     */

  

猜你喜欢

转载自www.cnblogs.com/q1359720840/p/10806901.html