首页 > 编程语言 >接口Map源码阅读与分析

接口Map源码阅读与分析

时间:2024-09-15 21:55:31浏览次数:1  
标签:Map return oldValue 接口 源码 key null newValue remappingFunction

 

 

computeIfPresent

用途:这是一个针对已经存在的键值对进行更新的方法,如果旧值存在,则使用key和旧值去计算出新值进行更新

具体逻辑如下:

XX

<流程图占位>

 default V computeIfPresent(K key,
            BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
        Objects.requireNonNull(remappingFunction);
        V oldValue;
        if ((oldValue = get(key)) != null) {
            V newValue = remappingFunction.apply(key, oldValue);
            if (newValue != null) {
                put(key, newValue);
                return newValue;
            } else {
                remove(key);
                return null;
            }
        } else {
            return null;
        }
    }

 

标签:Map,return,oldValue,接口,源码,key,null,newValue,remappingFunction
From: https://www.cnblogs.com/baokang/p/18415717

相关文章