No, there isn’t a way to do this, or else it would be built into Java. The type system isn’t strong enough to express this sort of thing.
More Related Contents:
- Why don’t Java Generics support primitive types?
- Difference between List, List, List, List, and List
- Possible heap pollution via varargs parameter
- Why does javac complain about generics unrelated to the class’ type arguments? [duplicate]
- Generics compiles and runs in Eclipse, but doesn’t compile in javac
- How to avoid type safety warnings with Hibernate HQL results?
- Cast Object to Generic Type for returning
- How to cast List to List
- How do I clone a generic List in Java?
- Java generics T vs Object
- How to Autowire Bean of generic type in Spring?
- Calling static generic methods
- Bounded-wildcard related compiler error
- Mockito.any() pass Interface with Generics
- Dynamic Generic Typing in Java
- Any simple way to explain why I cannot do List animals = new ArrayList()? [duplicate]
- Higher-kinded generics in Java
- How to make a Java Generic method static?
- Java generics, nested collection of wildcard
- Java generics – get class? [duplicate]
- Java interfaces and return types
- new ArrayList() failing in Java
- Java: Generic methods and numbers
- Generic method in Java without generic argument
- Generics compilation error with ternary operator in Java 8, but not in Java 7
- Using a generic type with Gson
- Java generics – ArrayList initialization
- How to write a generic method that takes two arguments of the same types in java?
- Java generics: wildcard vs type parameter?
- Provide an iterator over the contents of two lists simultaneously?