alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (AssistedInject.java)

This example Java source code file (AssistedInject.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

annotation, assistedinject, constructor, retention, target

The AssistedInject.java Java example source code

/**
 * Copyright (C) 2007 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.inject.assistedinject;

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

import com.google.inject.Inject;

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

/**
 * <p>
 * When used in tandem with {@link FactoryModuleBuilder}, constructors annotated with 
 * {@code @AssistedInject} indicate that multiple constructors can be injected, each with different
 * parameters. AssistedInject annotations should not be mixed with {@literal @}{@link Inject}
 * annotations. The assisted parameters must exactly match one corresponding factory method within
 * the factory interface, but the parameters do not need to be in the same order. Constructors
 * annotated with AssistedInject <b>are created by Guice and receive all the benefits
 * (such as AOP).
 * 
 * <p>
 * <strong>Obsolete Usage: When used in tandem with {@link FactoryProvider}, constructors
 * annotated with {@code @AssistedInject} trigger a "backwards compatibility mode". The assisted
 * parameters must exactly match one corresponding factory method within the factory interface and
 * all must be in the same order as listed in the factory. In this backwards compatable mode,
 * constructors annotated with AssistedInject <b>are not created by Guice and thus receive
 * none of the benefits.
 * 
 * <p>
 * Constructor parameters must be either supplied by the factory interface and marked with
 * <code>@Assisted, or they must be injectable.
 * 
 * @author jmourits@google.com (Jerome Mourits)
 * @author jessewilson@google.com (Jesse Wilson)
 */
@Target( { CONSTRUCTOR })
@Retention(RUNTIME)
public @interface AssistedInject {
}

Other Java examples (source code examples)

Here is a short list of links related to this Java AssistedInject.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.