java - Return generic list -


i want load generic list. therefore want use function :

public static <t> list<t> load() {     fileinputstream filestream = null;     list<t> toreturn = new arraylist<t>();     string fileextension = toreturn.getclass().getcomponenttype().getsimplename();     ... } 

if can see want type ("t"), search files these extensions. if call :

storageutil.<myclass>load(); 

i exception instead of getting "myclass" fileextension. what's wrong on code?

the problem generics in java don't work way - can't find type of t @ execution time due type erasure. if need type @ execution time, can add class<t> parameter:

public static <t> list<t> load(class<t> clazz) {     ... use class.newinstance() create new instance, etc } 

see java generics faq entry type erasure more information.


Comments

Popular posts from this blog

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -