cannot find symbol?

Discussion in 'Java' started by qwertmonkey@syberianoutpost.ru, May 4, 2013.

  1. Guest

    this is what I had in mind. The thing is that I wanted to get a typed object
    ~
    public T_Ctxt getCtxtDTO();
    ~
    instead of a flat one
    ~
    public Object getCtxtDTO();
    ~
    and even though I haven't had the chance/need to learn about generics and how
    they relate to reflection I have the (probably wrong) hunch that there should
    be a way to do that
    ~
    lbrtchx
    ~
    // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

    import java.util.Date;

    import java.io.IOException;

    import java.lang.reflect.Method;
    import java.lang.reflect.InvocationTargetException;

    // __
    class IADObj{
    private double d;
    private String aS;
    private Date Dt;
    // __
    IADObj(){}
    // __
    public void setCtxt(String[] aSAr){
    this.d = (new Double(aSAr[0])).doubleValue();
    this.aS = aSAr[1];
    this.Dt = new Date((new Long(aSAr[2])).longValue());
    }
    // __
    public String toString(){ return(" d: |" + d + "|, aS: |" + aS + "|, Dt: |" +
    Dt + "|"); }
    }

    // __
    class Ho3K{
    private String aS;
    Ho3K(){}
    public void setCtxt(String[] aSAr){ this.aS = aSAr[0]; }
    public String toString(){ return(" aS: |" + aS + "|"); }
    }

    // __
    interface verifiableCLIContext12<T_Ctxt>{
    public boolean verifyCtxt(String[] aSArs, Class<? extends T_Ctxt> TpArgK);
    // public T_Ctxt getCtxtDTO();
    public Object getCtxtDTO();
    }

    // __
    class DTO_T_Ctxt12<T_Ctxt> implements verifiableCLIContext12<T_Ctxt> {
    // private T_Ctxt tCtxt; // operating context

    private Object OCtxtObj; // operating context

    private final Class[] KParams = new Class[]{String[].class};

    // __
    DTO_T_Ctxt12(){ 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{
    OCtxtObj = (T_Ctxt)TpArgK.newInstance();
    Method VerMthd = (OCtxtObj.getClass()).getDeclaredMethod("setCtxt", KParams);
    VerMthd.invoke(OCtxtObj, new Object[]{aSAr});
    System.err.println("// __ |" + this.getClass() + "." +
    Thread.currentThread().getStackTrace()[1].getMethodName() + "|" + OCtxtObj + "|");
    }catch(InstantiationException InstX){ InstX.printStackTrace(System.err); }
    catch(IllegalAccessException IlglAxX){ IlglAxX.printStackTrace(System.err); }
    catch(NoSuchMethodException NMthddX){ NMthddX.printStackTrace(System.err); }
    catch(InvocationTargetException InvkTrgtX){ InvkTrgtX.printStackTrace(System.err); }

    }// (Is)
    // __
    return(Is);
    }

    // __
    public Object getCtxtDTO(){
    System.err.println("// __ |" + this.getClass() + "." +
    Thread.currentThread().getStackTrace()[1].getMethodName() + "|");
    return(OCtxtObj);
    }
    }

    // __
    public class DTO_T_Ctxt12Test{
    public static void main(String[] args) {
    String[] aSAr;
    Object RObj;
    // __
    System.err.println("// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ");
    IADObj IAD = new IADObj();
    aSAr = new String[]{"37", "abc",
    (new Long(System.currentTimeMillis())).toString()};
    DTO_T_Ctxt12<IADObj> DTO_IADObj = new DTO_T_Ctxt12<IADObj>();

    DTO_IADObj.verifyCtxt(aSAr, IAD.getClass());
    RObj = DTO_IADObj.getCtxtDTO();
    System.err.println("// __ |" + RObj.getClass() + "|" + RObj + "|");
    // __
    System.err.println("// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ");
    Ho3K Ho3 = new Ho3K();
    aSAr = new String[]{"Ho, ho, ho!"};
    DTO_T_Ctxt12<Ho3K> DTO_Ho3 = new DTO_T_Ctxt12<Ho3K>();

    DTO_Ho3.verifyCtxt(aSAr, Ho3.getClass());
    RObj = DTO_Ho3.getCtxtDTO();
    System.err.println("// __ |" + RObj.getClass() + "|" + RObj + "|");
    // __
    }
    }

    // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    , May 4, 2013
    #1
    1. Advertising

  2. markspace Guest

    On 5/4/2013 1:58 PM, wrote:
    > this is what I had in mind. The thing is that I wanted to get a typed object


    Generally speaking, that was TL;DR. SSCCE = SHORT self-contained
    compilable example.

    However, control-F allowed me to find some things in that huge mess you
    posted.


    > interface verifiableCLIContext12<T_Ctxt>{
    > public boolean verifyCtxt(String[] aSArs, Class<? extends T_Ctxt> TpArgK);
    > // public T_Ctxt getCtxtDTO();
    > public Object getCtxtDTO();
    > }


    public interface verifialbleCLIContext12<T> {
    public boolean verifyCtxt(String[] aSArs, Class<? extends T> TpArgK);
    public T getCtxtDTO();
    }

    looks much better than using the same identifier over and over again.

    > class DTO_T_Ctxt12<T_Ctxt> implements verifiableCLIContext12<T_Ctxt> {


    This is why you fail. Mostly overuse of the same crappy identifier
    until you can't read it any more. I barely could read it.

    class DTO_T_Ctxt12 implements verifiableCLIContext12<T_Ctxt> {

    needs to be concrete. Now these work:

    > private T_Ctxt tCtxt; // operating context


    as will this:

    > public T_Ctxt getCtxtDTO(){


    Etc. I didn't read the rest. I didn't verify any of the above to
    compile or test it.
    markspace, May 5, 2013
    #2
    1. Advertising

  3. Daniel Pitts Guest

    On 5/4/13 1:58 PM, wrote:
    > this is what I had in mind. The thing is that I wanted to get a typed object
    > ~
    > public T_Ctxt getCtxtDTO();
    > ~
    > instead of a flat one
    > ~
    > public Object getCtxtDTO();
    > ~
    > and even though I haven't had the chance/need to learn about generics and how
    > they relate to reflection I have the (probably wrong) hunch that there should
    > be a way to do that

    Reflection is usually bad. There are places for it, but if you can solve
    your problem without it, then do so.

    getCtxtDTO will return an Object of the static type T_Ctxt, but T_Ctxt
    has no information about it, other than it extends Object. In order to
    know more about it, you need an interface or base-class.

    class Foo<T_Ctxt> in Java is *not* the same as in C++. Templates are not
    even closely possible in Java. I will say it one last time. You need to
    use an interface.

    Perhaps you should read about Generics, since that is what you're trying
    (and failing) to use. A great introduction is here:

    http://docs.oracle.com/javase/tutorial/extra/generics/

    Read that, and one of your problems will be solved.

    > ~
    > lbrtchx
    > ~
    > // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    >
    > import java.util.Date;
    >
    > import java.io.IOException;
    >
    > import java.lang.reflect.Method;
    > import java.lang.reflect.InvocationTargetException;
    >
    > // __
    > class IADObj{
    > private double d;
    > private String aS;
    > private Date Dt;
    > // __
    > IADObj(){}
    > // __
    > public void setCtxt(String[] aSAr){
    > this.d = (new Double(aSAr[0])).doubleValue();
    > this.aS = aSAr[1];
    > this.Dt = new Date((new Long(aSAr[2])).longValue());
    > }
    > // __
    > public String toString(){ return(" d: |" + d + "|, aS: |" + aS + "|, Dt: |" +
    > Dt + "|"); }
    > }
    >
    > // __
    > class Ho3K{
    > private String aS;
    > Ho3K(){}
    > public void setCtxt(String[] aSAr){ this.aS = aSAr[0]; }
    > public String toString(){ return(" aS: |" + aS + "|"); }
    > }
    >
    > // __
    > interface verifiableCLIContext12<T_Ctxt>{
    > public boolean verifyCtxt(String[] aSArs, Class<? extends T_Ctxt> TpArgK);
    > // public T_Ctxt getCtxtDTO();
    > public Object getCtxtDTO();
    > }
    >
    > // __
    > class DTO_T_Ctxt12<T_Ctxt> implements verifiableCLIContext12<T_Ctxt> {
    > // private T_Ctxt tCtxt; // operating context
    >
    > private Object OCtxtObj; // operating context
    >
    > private final Class[] KParams = new Class[]{String[].class};
    >
    > // __
    > DTO_T_Ctxt12(){ 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{
    > OCtxtObj = (T_Ctxt)TpArgK.newInstance();
    > Method VerMthd = (OCtxtObj.getClass()).getDeclaredMethod("setCtxt", KParams);
    > VerMthd.invoke(OCtxtObj, new Object[]{aSAr});
    > System.err.println("// __ |" + this.getClass() + "." +
    > Thread.currentThread().getStackTrace()[1].getMethodName() + "|" + OCtxtObj + "|");
    > }catch(InstantiationException InstX){ InstX.printStackTrace(System.err); }
    > catch(IllegalAccessException IlglAxX){ IlglAxX.printStackTrace(System.err); }
    > catch(NoSuchMethodException NMthddX){ NMthddX.printStackTrace(System.err); }
    > catch(InvocationTargetException InvkTrgtX){ InvkTrgtX.printStackTrace(System.err); }
    >
    > }// (Is)
    > // __
    > return(Is);
    > }
    >
    > // __
    > public Object getCtxtDTO(){
    > System.err.println("// __ |" + this.getClass() + "." +
    > Thread.currentThread().getStackTrace()[1].getMethodName() + "|");
    > return(OCtxtObj);
    > }
    > }
    >
    > // __
    > public class DTO_T_Ctxt12Test{
    > public static void main(String[] args) {
    > String[] aSAr;
    > Object RObj;
    > // __
    > System.err.println("// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ");
    > IADObj IAD = new IADObj();
    > aSAr = new String[]{"37", "abc",
    > (new Long(System.currentTimeMillis())).toString()};
    > DTO_T_Ctxt12<IADObj> DTO_IADObj = new DTO_T_Ctxt12<IADObj>();
    >
    > DTO_IADObj.verifyCtxt(aSAr, IAD.getClass());
    > RObj = DTO_IADObj.getCtxtDTO();
    > System.err.println("// __ |" + RObj.getClass() + "|" + RObj + "|");
    > // __
    > System.err.println("// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ");
    > Ho3K Ho3 = new Ho3K();
    > aSAr = new String[]{"Ho, ho, ho!"};
    > DTO_T_Ctxt12<Ho3K> DTO_Ho3 = new DTO_T_Ctxt12<Ho3K>();
    >
    > DTO_Ho3.verifyCtxt(aSAr, Ho3.getClass());
    > RObj = DTO_Ho3.getCtxtDTO();
    > System.err.println("// __ |" + RObj.getClass() + "|" + RObj + "|");
    > // __
    > }
    > }
    >
    > // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
    >
    Daniel Pitts, May 5, 2013
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny
    Replies:
    1
    Views:
    4,662
    Andrew Thompson
    May 26, 2004
  2. Replies:
    5
    Views:
    6,523
    Tilman Bohn
    Dec 16, 2004
  3. luch
    Replies:
    5
    Views:
    6,333
  4. fybar

    cannot find symbol

    fybar, Apr 25, 2006, in forum: Java
    Replies:
    6
    Views:
    9,228
    Oliver Wong
    Apr 25, 2006
  5. Replies:
    6
    Views:
    1,722
Loading...

Share This Page