Code example for ConcurrentHashMap

Methods: put

    public <T> T get(Class<T> type) {
        return type.cast(data.get(type));
    public <T> T set(Class<T> type, T instance) {
        return type.cast(data.put(type,instance));
     * Overwrites the value only if the current value is null. 
     * @return 
     *      If the value was null, return the {@code instance} value. 
     *      Otherwise return the current value, which is non-null. 
    public <T> T setIfNull(Class<T> type, T instance) {
        Object o = data.putIfAbsent(type, instance);
        if (o!=null)    return type.cast(o);
        return instance;
Contextual code suggestions in your IDE  Get Codota for Java