Java does not support this syntax, but if your goal is to create a collection whose type is determined by the type of the instance, create a typed method, for example:
public static <T> List<T> createList(T object) {
List<T> list = new ArrayList<T>();
list.add(object);
return list;
}
No matter what type you pass, the type of the returned list will be determined. This is not a run-time definition - it is a compile-time check, but it is closest to how I interpret your intent.
source
share