Return different type of data from a method in java?
I create various return types using enum. It doesn’t defined automatically. That implementation look like factory pattern. public enum SmartReturn { IntegerType, DoubleType; @SuppressWarnings(“unchecked”) public <T> T comeback(String value) { switch (this) { case IntegerType: return (T) Integer.valueOf(value); case DoubleType: return (T) Double.valueOf(value); default: return null; } } } Unit Test: public class MultipleReturnTypeTest { … Read more