在开发中,对 Interface 的使用总是避不开的,或多或少都会涉及到。比如在 Android 中各种 Listener 都是 Interface,

    在 Java1.8 以前,不行!

    1. /*
    2. * *********** All Rights Reserved. ************
    3. * 作者昵称:Shawn.XiaFei
    4. * 联系邮箱:shawn.xiafei@foxmail.com
    5. * 微信订阅:灰灰的Rom笔记
    6. * 博客链接:https://www.jianshu.com/u/22310adb59a8
    7. * 上次修改:2019-07-28 12:35
    8. * *********** All Rights Reserved. ************
    9. */
    10. package shawn.xiafei.database;
    11. /**
    12. * 数据解密
    13. */
    14. public interface IDecipher {
    15. byte[] deBlob(final byte[] src);
    16. String deString(final String src);
    17. short deShort(final short src);
    18. int deInt(final int src);
    19. long deLong(final long src);
    20. float deFloat(final float src);
    21. double deDouble(final double src);
    22. }

    Java1.8 以后,可以!

    1. /*
    2. * *********** All Rights Reserved. ************
    3. * 作者昵称:Shawn.XiaFei
    4. * 联系邮箱:shawn.xiafei@foxmail.com
    5. * 微信订阅:灰灰的Rom笔记
    6. * 博客链接:https://www.jianshu.com/u/22310adb59a8
    7. * 上次修改:2019-07-28 12:35
    8. * *********** All Rights Reserved. ************
    9. */
    10. package shawn.xiafei.database;
    11. /**
    12. * 数据解密
    13. */
    14. public interface IDecipher {
    15. default boolean isChinese(final byte ch) {
    16. return (ch & 0x80) != 0;
    17. }
    18. byte[] deBlob(final byte[] src);
    19. String deString(final String src);
    20. short deShort(final short src);
    21. int deInt(final int src);
    22. long deLong(final long src);
    23. float deFloat(final float src);
    24. double deDouble(final double src);
    25. }