Is it possible to instantiate an object of generic type in Java or C#? -


For example, in Java, if I have a parameterized class, is it possible to do the following?

  Public Class Mayclass & lt; T & gt; {Public invalid aMethod}. T object = new T (); ..} ..}  

In Java, I think this is not possible, because the compiler does not know how the constructor calls. But in C # I do not know the language and I have read that there can be many dark things, so I was thinking ..

This is possible in C # if you are defining a type of constraint for the parameter constructor.

  Public Class MyClass & lt; T & gt; Where T: new () {public zero aMethod {. T object = new T (); ..} ..}  


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -