I have a program on my computer that simulates a server on the internet and the fake server needs to be able to send multiple data types to some classes. Like for instance at one point of the program the server needs to send an int to a class then convert that int to a string and send it to another.
Basically what I am asking is if a method can have multiple data types for an input(Does this make sense? if not ill try to explain better). Is there any way to do this without creating many different methods?
Edit: Also is there a way to tell the difference between the types passed in (to prevent errors)
If I understand correctly, you’re asking if a method
foo()can have multiple different inputs for its parametersThat way
foo(Integer i)andfoo(String s)are encased in the same method.The answer: yes, but it’s not pretty
foo(Object o)Is your method declaration
Now you need to sort out the different types of possibilities
Just chain those else/if statements for the desired result.