Type parameters can only be defined on
- (i.e. classes / interfaces),
- and
- Constructors.
You need a type parameter for a local block, which is not possible.
Yes, I sometimes missed something like that.
But there really is no problem with the fact that the method is not nested in it - if it is a performance bottleneck in which inlineation will help, Hotspot will turn it on again (without worrying about type).
In addition, the presence of a separate method allows you to give it a descriptive name.
Just an idea if you need it often:
interface DoWithFM { void <T> run(FactManager<T> t); } ... for (FactManager<?> factManager : factManagers) { ... new DoWithFM() { public <T> run(FactManager<T> factManager) { for (T fact : factManager) { factManager.doSomething(fact); } }.run(factManager); ... } ...
Paŭlo Ebermann
source share