Here is a trivial example that I put together:
private static <T> T getValue(T defaultValue) { if (defaultValue instanceof Boolean) { return (T) true; } return defaultValue; }
Essentially, I want to return "true" if T is of type boolean. However, I get a compilation error that boolean cannot distinguish from T.
How can I do it?
Also, is there a way to check if type T is type boolean? Best wishes.
Peter source share