Typesafety lost for template class (bug?)
Hi all,
I have this template class BlResponse<T> containing a List<String>.
When I call the contructor as
BlResponse<Long> typesafeObject =new BlResponse<Long>();
then the following statement returns a List<String> typesafeObject.getMessages();
But, when I do this BlResponse duplicateObject = typesafeObject;
then the following statement no longer returns a List<String> but a List, and all typesafety is gone duplicateObject.getMessages();
I've been using both Netbeans 5 as Eclipse 3.1, and both act the same. About a month ago I posted this as a possible bug, but I haven't heard anything about it since. So I was wondering, is this a bug? Or can it be solved in another way?
Here's the complete code:
import java.util.LinkedList;
import java.util.List;
publicclass BlResponse<T>{
private List<String> messages;
private T object;
public BlResponse(){
messages =new LinkedList<String>();
}
public T getObject(){
return object;
}
publicvoid setObject(T object){
this.object = object;
}
public List<String> getMessages(){
return messages;
}
publicvoid setMessages(List<String> messages){
this.messages = messages;
}
publicstaticvoid main(String[] args){
BlResponse<Long> typesafeObject =new BlResponse<Long>();
typesafeObject.getMessages();// getMessages returns List<String>
BlResponse duplicateObject = typesafeObject;
duplicateObject.getMessages();// BUG: getMessages returns List !
}
}
cheers, pj

