jdk8四种函数式接口

/**
 * 
 */
package com.gewb;

/**
 * @author Bingo.Ge
 * @date 2020年6月6日
 */
public class TestDemo {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		// 即使用string的static方法valueOf来当作IMessage接口的实现
//		IMessage<Integer, String> msg = String :: valueOf;
//		String str = msg.zhuanhuan(1000);
//		System.out.println(str.replaceAll("0", "9"));
		
//		// 使用字符串的toUpperCase方法来做upper的实现方法
//		IMessage2<String> msg = "hello" :: toUpperCase;
//		String upper = msg.upper();
//		
//		System.out.println(upper);
		
		
//		IMessage3<String> msg = String :: compareTo;
//		int compare = msg.compare("A", "B");
//		
//		System.out.println(compare);
		
		
		IMessage4<Book> msg = Book :: new;
		Book book = msg.create("jdk8自学成才", 18.0);
		System.out.println(book);
		
		
	}

}


class Book {
	private String title;
	private double price;
	
	public Book(String title, double price) {
		this.title = title;
		this.price = price;
	}
	
	@Override
	public String toString() {
		return "书名:" + this.title + " 价格:" + this.price;
	}
}



@FunctionalInterface
interface IMessage4<C> {
	public C create(String  t, double p);
}

interface IMessage<P, R> {
	public R zhuanhuan(P p);
}

@FunctionalInterface  // 表示这个接口是函数式接口,只能定义一个方法
interface IMessage2<R> {
	public R upper();
}

@FunctionalInterface
interface IMessage3<P> {
	public int compare(P p1, P p2);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值