No, you cannot write a method that returns different types based on some parameter the way you want to do it. Note that this idea is also not very useful - you have to assign the result of the method to something (a variable for example), now if you don't know the type of the return value before runtime, then how are you going to determine the type of the variable you want to assign the value to at the moment you're writing the program?
If you make that variable an Object, so that anything fits into it, then the method that returns the unknown type is useless, because you're going to ignore the type of the return value anyway.
Note that there is a distinction between the static type of a variable and the runtime type of the thing that the variable is pointing to. You can do this:
The static type of the variable "obj" is Object, but the dynamic type of the object it refers to is Integer.
If you need a Map that accepts only specific types for the keys and values, then
you should use generics: