有没有什么方法可以在运行时创建泛型类型的特定实例?
例如.
Cacheable instance = getCacheable(someInput);
getCacheble方法将返回Cacheable的实例.所以它可以是实现Cacheable的任何类.例如Customer,Product等.现在我想创建一个由getCacheable返回的特定类型的列表,如下所示.这可能吗?如果是的话怎么做?
List extends Cacheable> cacheList = new ArrayList<>();
我想ArrayList
基于getCacheable方法返回的实例创建.