java函数式接口加lambda表达式进制转换练习

时间:2020-07-08 13:13:44   收藏:0   阅读:56
/*
    1.	定义一个函数式接口NumberToString,其中抽象方法String convert(int num),使用注解@FunctionalInterface
    2.	在测试类中定义static void decToHex(int num ,NumberToString nts),
        该方法的预期行为是使用nts将一个十进制整数转换成十六进制表示的字符串,tips:已知该行为与Integer类中的toHexString方法一致
    3.	测试decToHex (),使用方法引用完成需求

 */
public class 练习3 {
    public static void main(String[] args) {
        decToHex(12,Integer::toHexString);
    }
    @FunctionalInterface
    public interface NumberToString{
        String convert(int num);
    }
    static void decToHex(int num ,NumberToString nts){
        //String s = Integer.toHexString(num);
        String st = nts.convert(num);
        System.out.println(st);
    }
}

  

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!