JDK1.8 新特性学习
Posted wcgstudy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();
以上是关于JDK1.8 新特性学习的主要内容,如果未能解决你的问题,请参考以下文章