0

This is the code I have and using Java/Selenium. How to return a new instance of T? For non generic method the return would be return new ClassName(Driver);

In C# its >> return (T)Activator.CreateInstance(typeof(T), Driver);

public <T> T MethodName(String pane) throws InterruptedException
{
    // Some operations take place here

    Thread.sleep(3000); 

    **// I want to return new T(Driver); How to to do this????**
}
user10829672
  • 45
  • 1
  • 9
  • You can't create new instances of generic types in Java due to type erasure. But there are ways to create new instance when having `Class` instance. This may help: https://stackoverflow.com/questions/75175/create-instance-of-generic-type-in-java – geobreze Aug 03 '21 at 22:13

0 Answers0