In C #, I can put a type constraint on a generic parameter, which requires a generic type to have a constructor without parameters without parameters. Can I do the same in Java?
In C #:
public static T SomeMethodThatDoesSomeStuff<T>() where T : class, new() {
Class restrictions and new () mean that T must be a class that can be called by a new operator with zero parameters. What I know little about Java generics, I can use extends
to indicate the required superclass. Can I use this (or any other supported operation) to achieve the above functions?
source share