Re: Created a class dynamically but could not use it to create typed
objects
On May 16, 10:35 pm, Arne Vajh=F8j <a...@vajhoej.dk> wrote:
You can reload a class by using a new classloader (and let the
old classloader and all objects of classes loaded by it go to GC).
~
OK, I think my seconds thoughts were not baseless, as tomcat showed
to me generics don't appear to depend solely on compile time checks
and/or there definitely is a way around it
~
I think there should be a way to load and handle generic classes at
run time. Tomcat does it
~
This is what I did to see what was going on with tc classloaders and
generic classes:
~
1) in catalina.sh I declared: CATALINA_OPTS=-verbose:class
~
2) in /webapps/ROOT/META-INF/context.xml I set: reloadable="true"
~
3) then I used some test classes to play with tc loaders and see live
how it would indeed reload changed and totally new class, even generic
ones
package test.k00;
public class K00{
public int i0;
public long l0;
}
package test.k00;
public class K02{
public int i2;
public String aS2;
}
package test.k00;
import java.util.*;
// __
public class GenK00<T>{
private String aS;
public ArrayList<T> ALK00 = new ArrayList<T>();
// __
public GenK00(String aS){
this.aS = aS;
}
}
~
4) Inside of index.jsp I included:
<p>
Loading Generic classes:<br/>
<%@page import="test.k00.*"%>
<%
GenK00<String> GK0 = new GenK00<String>("<String>");
GK0.ALK00.add("blue");
GK0.ALK00.add("rote");
GK0.ALK00.add("blanco");
K00 k0 = new K00();
k0.i0 = 0;
k0.l0 = 0L;
K00 k1 = new K00();
k1.i0 = 1;
k1.l0 = 1L;
K00 k2 = new K00();
k2.i0 = 2;
k2.l0 = 2L;
GenK00<K00> GK2 = new GenK00<K00>("K00");
GK2.ALK00.add(k0);
GK2.ALK00.add(k1);
GK2.ALK00.add(k2);
GK2.ALK00.add(k1);
K02 J = new K02();
J.i2 = 4748;
J.aS2 = "aS2";
%>
<br/>
GK0.ALK00.size(): <%=GK0.ALK00.size()%>
<br/>
GK0.ALK00: <%=GK0.ALK00%>
<br/>
GK2.ALK00.size(): <%=GK2.ALK00.size()%>
<br/>
GK2.ALK00: <%=GK2.ALK00%>
<br/>
J: <%=J%>
</p>
So all that I needs to be done is look into tc classloaders
Am I missing anything here?
lbrtchx