is there any way to make a new instance of generic type in a generic method?
some thing like
or is it foolish to make a new instance while we don't know what is the type of that instance at run time?
<T> void receive(List <T> a)
You can't create new instance from generic type, because may be situation when generic type may be have no public constructors.
also we cant assure that the generic type have a constructor of the type we use
However, I read about this problem. You can use (Class<E> clazz).newInstance();,
but it makes no sense.
think its using reflection ...
Yes,it is. This is reflection.
I don't understand why do you want to do this? Why do you want to use this code?
i don't want to use it in actual code, but now i am learning generics in java and try to experiment with that.
thanks petr for quick reply