Here's a generic, non-dependent bean class:
@ApplicationScoped
public class FavouriteChooser<T> {
public T getFavourite() {
// ...
}
}
How many instances of this bean will there be in the application?
Here is an injection site:
@Inject
private FavouriteChooser<String> favouriteWord;
And here's another:
@Inject
private FavouriteChooser<Integer> favouriteNumber;
Would you like to change your answer? :D
Ooh, and here's another:
@Inject
private FavouriteChooser<CharSequence> favouriteLetters;
EDIT. If you want a solution, i would suggest making your generic class abstract, and adding concrete subclasses which bind the type. So:
public abstract class MyProducer<T> {...}
@Named
@SessionScoped
public class MyStringProducer extends MyProducer<String> {}
@Named
@SessionScoped
public class MyIntegerProducer extends MyProducer<Integer> {}
It's boilerplate, but it's only three lines per type. Bear in mind that would give you one instance per session per type, which you might not want.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…