zoukankan      html  css  js  c++  java
  • JDK1.8 新特性学习(一)

    JDK1.8 引入了函数式编程lambda,使编程变得简洁.

    可以用lambda表达式替代匿名函数

    package javaJVM;
    
    import java.awt.Event;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    public class Test1 extends JFrame{
        
        private JButton jb;
        
        public Test1() {
            this.setBounds(200,200,400,300);
            this.setTitle("lambda测试");
            
            jb = new JButton("click");
            this.add(jb);
            this.setVisible(true);
            /*jb.addActionListener(new ActionListener() {
                
                @Override
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub
                    System.out.println("click");
                }
            });*/
            jb.addActionListener(Event -> System.out.println("hello"));
            
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            
        }
        
        public static void main(String[] args) {
            
            new Test1();
            
        }
        
    
    }

    package javaJVM;

    import java.awt.Event;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JButton;
    import javax.swing.JFrame;

    public class Test1 extends JFrame{
        
        private JButton jb;
        
        public Test1() {
            this.setBounds(200,200,400,300);
            this.setTitle("lambda测试");
            
            jb = new JButton("click");
            this.add(jb);
            this.setVisible(true);
            /*jb.addActionListener(new ActionListener() {
                
                @Override
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub
                    System.out.println("click");
                }
            });*/
            jb.addActionListener(Event -> System.out.println("hello"));
            
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            
        }
        
        public static void main(String[] args) {
            
            new Test1();
            
        }
        

    }

  • 相关阅读:
    龙年新作:水印文字添加工具源码摘要
    C语言关键字 浪里白条:goto
    继续聊WPF——自定义命令
    CSS3新的鼠标样式介绍
    C语言深入理解 常量与变量
    XCode 4 不能运行的解决办法
    Runtime专题:详解IOS开发应用之并发Dispatch Queues
    C语言关键字 乱世枭雄:static与extern
    一步步带你做vue后台管理框架(一)——介绍框架
    怎么在谷歌浏览器中安装.crx扩展名的离线Chrome插件?
  • 原文地址:https://www.cnblogs.com/wcgstudy/p/11216480.html
Copyright © 2011-2022 走看看