/**
*
*/
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);
}