Q
qwertmonkey
Basically I am passing a String array to a method (verify) defined in a
generic way in an interface in order to create an object of a certain type
I am checking that the object of the correct type is created but when I try
to call a method java tells me "cannot find symbol"
I squinted at it for a while, but can't see what is wrong with it
What is wrong with this code? How do you fix that problem? Does it relate
to the use of generic declarations and/or reflection?
thanks,
lbrtchx
comp.lang.java.programmer: cannot find symbol?
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
import java.util.Date;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
// __ mock/test object
class IADObj{
private int d;
private String aS;
private Date Dt;
// __
IADObj(){}
// __
public void setCtxt(int d, String aS, long lTm){
this.d = d;
this.aS = aS;
this.Dt = new Date(lTm);
}
// __
public String toString(){ return("// __ d: |" + d + "|, aS: |" + aS +
"|, Dt: |" + Dt + "|"); }
}
// __
interface verifiableCLIContext06<T_Ctxt>{
public boolean verifyCtxt(String[] aSArs, Class<? extends T_Ctxt> TpArgK);
public T_Ctxt getCtxtDTO();
}
// __
class DTO_T_Ctxt06<T_Ctxt> implements verifiableCLIContext06<T_Ctxt> {
private T_Ctxt tCtxt; // operating context
// __
DTO_T_Ctxt06(){ System.err.println("// __ object created: |" +
getTimeStamp() + "|"); }
// __
private String getTimeStamp(){ return((new Date()).toString()); }
// __
public boolean verifyCtxt(String[] aSAr, Class<? extends T_Ctxt> TpArgK){
int iArSz= Integer.MIN_VALUE;
boolean Is = ((aSAr != null) && ((iArSz = aSAr.length) > 0));
if(Is){
for(int i = 0; (i < iArSz); ++i){
System.err.println("// __ aSAr[" + i + "]: |" + aSAr + "|");
}
// __
try{
tCtxt = (T_Ctxt)TpArgK.newInstance();
System.err.println("// __ tCtxt.getClass(): |" + tCtxt.getClass() + "|");
/*
tCtxt.setCtxt((new Integer(aSAr[0])).intValue(), aSAr[1],
(new Long(aSAr[0])).longValue());
cannot find symbol
symbol : method setCtxt(int,java.lang.String,long)
location: class java.lang.Object
tCtxt.setCtxt((new Integer(aSAr[0])).intValue(), aSAr[1],
(new Long(aSAr[0])).longValue());
^
*/
}catch(InstantiationException InstX){ InstX.printStackTrace(System.err); }
catch(IllegalAccessException IlglAxX){ IlglAxX.printStackTrace(); }
}// (Is)
// __
return(Is);
}
// __
public T_Ctxt getCtxtDTO(){ return(tCtxt); }
}
// __
public class DTO_T_Ctxt06Test{
public static void main(String[] args) {
IADObj IAD = new IADObj();
String[] aSAr = new String[]{"37", "abc", (new Date()).toString()};
DTO_T_Ctxt06<IADObj> DTO_T_Ctxt06 = new DTO_T_Ctxt06<IADObj>();
DTO_T_Ctxt06.verifyCtxt(aSAr, IAD.getClass());
}
}
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
generic way in an interface in order to create an object of a certain type
I am checking that the object of the correct type is created but when I try
to call a method java tells me "cannot find symbol"
I squinted at it for a while, but can't see what is wrong with it
What is wrong with this code? How do you fix that problem? Does it relate
to the use of generic declarations and/or reflection?
thanks,
lbrtchx
comp.lang.java.programmer: cannot find symbol?
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
import java.util.Date;
import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
// __ mock/test object
class IADObj{
private int d;
private String aS;
private Date Dt;
// __
IADObj(){}
// __
public void setCtxt(int d, String aS, long lTm){
this.d = d;
this.aS = aS;
this.Dt = new Date(lTm);
}
// __
public String toString(){ return("// __ d: |" + d + "|, aS: |" + aS +
"|, Dt: |" + Dt + "|"); }
}
// __
interface verifiableCLIContext06<T_Ctxt>{
public boolean verifyCtxt(String[] aSArs, Class<? extends T_Ctxt> TpArgK);
public T_Ctxt getCtxtDTO();
}
// __
class DTO_T_Ctxt06<T_Ctxt> implements verifiableCLIContext06<T_Ctxt> {
private T_Ctxt tCtxt; // operating context
// __
DTO_T_Ctxt06(){ System.err.println("// __ object created: |" +
getTimeStamp() + "|"); }
// __
private String getTimeStamp(){ return((new Date()).toString()); }
// __
public boolean verifyCtxt(String[] aSAr, Class<? extends T_Ctxt> TpArgK){
int iArSz= Integer.MIN_VALUE;
boolean Is = ((aSAr != null) && ((iArSz = aSAr.length) > 0));
if(Is){
for(int i = 0; (i < iArSz); ++i){
System.err.println("// __ aSAr[" + i + "]: |" + aSAr + "|");
}
// __
try{
tCtxt = (T_Ctxt)TpArgK.newInstance();
System.err.println("// __ tCtxt.getClass(): |" + tCtxt.getClass() + "|");
/*
tCtxt.setCtxt((new Integer(aSAr[0])).intValue(), aSAr[1],
(new Long(aSAr[0])).longValue());
cannot find symbol
symbol : method setCtxt(int,java.lang.String,long)
location: class java.lang.Object
tCtxt.setCtxt((new Integer(aSAr[0])).intValue(), aSAr[1],
(new Long(aSAr[0])).longValue());
^
*/
}catch(InstantiationException InstX){ InstX.printStackTrace(System.err); }
catch(IllegalAccessException IlglAxX){ IlglAxX.printStackTrace(); }
}// (Is)
// __
return(Is);
}
// __
public T_Ctxt getCtxtDTO(){ return(tCtxt); }
}
// __
public class DTO_T_Ctxt06Test{
public static void main(String[] args) {
IADObj IAD = new IADObj();
String[] aSAr = new String[]{"37", "abc", (new Date()).toString()};
DTO_T_Ctxt06<IADObj> DTO_T_Ctxt06 = new DTO_T_Ctxt06<IADObj>();
DTO_T_Ctxt06.verifyCtxt(aSAr, IAD.getClass());
}
}
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~