@FunctionalInterface是必须的吗
我的疑惑来源于源码中的函数式接口没有加@FunctionalInterface也可以支持lambda表达式
例如RedisTemplate的源码:
@Override public Boolean expire(K key, final long timeout, final TimeUnit unit) { byte[] rawKey = rawKey(key); long rawTimeout = TimeoutUtils.toMillis(timeout, unit); return execute(connection -> { try { return connection.pExpire(rawKey, rawTimeout); } catch (Exception e) { // Driver may not support pExpire or we may be running on Redis 2.4 return connection.expire(rawKey, TimeoutUtils.toSeconds(timeout, unit)); } }, true); }
execute的第一个参数使用了lambda表达式,而第一个参数却没有声明@FunctionalInterface:
@Nullable public <T> T execute(RedisCallback<T> action, boolean exposeConnection) { return execute(action, exposeConnection, false); }
/** * Callback interface for Redis 'low level' code. To be used with {@link RedisTemplate} execution methods, often as * anonymous classes within a method implementation. Usually, used for chaining several operations together ( * {@code get/set/trim etc...}. * * @author Costin Leau */ public interface RedisCallback<T> { /** * Gets called by {@link RedisTemplate} with an active Redis connection. Does not need to care about activating or * closing the connection or handling exceptions. * * @param connection active Redis connection * @return a result object or {@code null} if none * @throws DataAccessException */ @Nullable T doInRedis(RedisConnection connection) throws DataAccessException; }
bing搜索了一下:
人前不露怯,
远足不露财,
内外当整洁,
自奉须俭约。
标签:
入门
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理