P
P
pqgg7nwkd42016-10-23 18:19:31
Java
pqgg7nwkd4, 2016-10-23 18:19:31

How to perform an operation on operands of unknown types?

For example, take the + operation.
Need a feature like this:
Object plus(Object left, Object right) {...}
What:

plus(1, 3); // = 4 (Integer)
plus(1L, 3); // = 4 (Long)
plus(1L, "test"); // = "1test" (String)
plus(1, new Date()); // Exception

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question