All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.inject.multibindings.ProvidesIntoOptional Maven / Gradle / Ivy

package com.google.inject.multibindings;

import com.google.inject.Module;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * Annotates methods of a {@link Module} to add items to a {@link Multibinder}.
 * The method's return type and binding annotation determines what Optional this will
 * contribute to. For example,
 *
 * 
 * {@literal @}ProvidesIntoOptional(DEFAULT)
 * {@literal @}Named("url")
 * String provideFooUrl(FooManager fm) { returm fm.getUrl(); }
 *
 * {@literal @}ProvidesIntoOptional(ACTUAL)
 * {@literal @}Named("url")
 * String provideBarUrl(BarManager bm) { return bm.getUrl(); }
 * 
* * will set the default value of {@code @Named("url") Optional} to foo's URL, * and then override it to bar's URL. */ @Documented @Target(METHOD) @Retention(RUNTIME) public @interface ProvidesIntoOptional { /** * Specifies if the binding is for the actual or default value. */ Type value(); enum Type { /** * Corresponds to {@link OptionalBinder#setBinding}. */ ACTUAL, /** * Corresponds to {@link OptionalBinder#setDefault}. */ DEFAULT } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy