I think you're confusing autoboxing with type inference.
Type inference is when the compiler can tell what type it should use on a generic method on its own, from the variables used when calling the method.
For example if you have the following method:
public <T extends SomeClass> T process(T obj) {
// call some methods of SomeClass on obj to process it here
return obj;
}
and then call it like:
SomeChildClass a = new SomeChildClass(); // SomeChildClass extends SomeClass
a = process(a);
the inferred type will be SomeChildClass;
The type can be inferred from the parameters or from the return type, as is in your example. But it's not always obvious to the compiler what type it should use. If that happens you can force the type by using the method this.<Double>getAnything(int flag)
that you described. This usually happens in situations like this:
public <T> List<T> getSomeList() {
// implementation
}
public void processList(List<SomeClass> list) {
// implementation
}
and calling
processList(getSomeList()); // compiler error: cannot convert List<Object> to List<SomeClass>
In cases like this you may need to force the type parameter.
All this being said, please take into consideration everything that polygenelubricants said as well, as he makes some very good points regarding your code and explains what autoboxing is (it's related to primitive wrapper classes like Integer for int, and Double for double).