Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #23816 > unrolled thread
| Started by | qwertmonkey@syberianoutpost.ru |
|---|---|
| First post | 2013-05-04 04:01 +0000 |
| Last post | 2013-05-05 13:09 +0200 |
| Articles | 9 — 9 participants |
Back to article view | Back to comp.lang.java.programmer
cannot find symbol? qwertmonkey@syberianoutpost.ru - 2013-05-04 04:01 +0000
Re: cannot find symbol? Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-03 21:54 -0700
Re: cannot find symbol? lipska the kat <"nospam at neversurrender dot co dot uk"> - 2013-05-04 09:16 +0100
Re: cannot find symbol? Joerg Meier <joergmmeier@arcor.de> - 2013-05-04 14:49 +0200
Re: cannot find symbol? Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-05-04 09:14 -0400
Re: cannot find symbol? Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-05-06 05:42 -0300
Re: cannot find symbol? Arne Vajhøj <arne@vajhoej.dk> - 2013-05-04 21:31 -0400
Re: cannot find symbol? markspace <markspace@nospam.nospam> - 2013-05-04 18:34 -0700
Re: cannot find symbol? Robert Klemme <shortcutter@googlemail.com> - 2013-05-05 13:09 +0200
| From | qwertmonkey@syberianoutpost.ru |
|---|---|
| Date | 2013-05-04 04:01 +0000 |
| Subject | cannot find symbol? |
| Message-ID | <km2178$3h2$1@speranza.aioe.org> |
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[i] + "|");
}
// __
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());
}
}
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
[toc] | [next] | [standalone]
| From | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| Date | 2013-05-03 21:54 -0700 |
| Message-ID | <Mv0ht.26140$GU1.13015@newsfe18.iad> |
| In reply to | #23816 |
On 5/3/13 9:01 PM, qwertmonkey@syberianoutpost.ru wrote:
> 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[i] + "|");
> }
> // __
> 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());
> }
> }
> // ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
>
Try reducing your problem to an SSCCE <http://sscce.org>. It is
difficult to follow those poorly named mock classes and interfaces.
On an unrelated note, what the hell convention is that? DTO? T_? Hell,
underscores in class names? This looks like it was copied from C++ code
which was copied from C code.
Actually, now that I say that, are you expecting generics to work like
templates in C++? They don't.
The DTO_T_Ctxt06 object (which has the same name as the class, bad and
confusing) only knows about the "?". It doesn't know about the specific
subclass you've chosen.
What you want is an interface.
public interface ContextAware {
void setContext(int data, String string, long time);
}
public class Adjective implements ContextAware {
private int data;
private String string;
private Date date;
public void setContext(int data, String string, long time) {
this.data = data;
this.string = string;
this.date = new Date(time);
}
}
public class ContextVerifier {
public verifyContext(String[] strings, ContextAware target) {
target.setContext(
Integer.parseInt(strings[0]),
strings[1],
Long.parseLong(strings[2]);
}
}
public class Test {
public static void main(String...args) {
final String[] args = {
"37",
"abc",
String.valueOf(System.currentTimeMillies())
};
final ContextVerifier cv = new ContextVerifier();
cv.verifyContext(args, new Adjective();
}
}
Well, would you look at that. You no longer have to deal with Class
tokens, instantiation, exceptions, or generics! A much cleaner program.
Untested, but the main concept should be clear.
Hope this helps,
Daniel.
[toc] | [prev] | [next] | [standalone]
| From | lipska the kat <"nospam at neversurrender dot co dot uk"> |
|---|---|
| Date | 2013-05-04 09:16 +0100 |
| Message-ID | <cPqdnfwaQtFxXhnMnZ2dnUVZ8radnZ2d@bt.com> |
| In reply to | #23816 |
On 04/05/13 05:01, qwertmonkey@syberianoutpost.ru wrote: > 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? Firstly, looking at this code gave me a headache :-( Secondly There is no reflection so the import statements import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; are not required Thirdly change tCtxt.setCtxt((new Integer(aSAr[0])).intValue(), aSAr[1], (new Long(aSAr[0])).longValue()); to ((IADObj) tCtxt).setCtxt((new Integer(aSAr[0])).intValue(), aSAr[1], (new Long(aSAr[0])).longValue()); and the code will compile and run although it really should be re-written as is is *horrible* for reasons explained elsewhere in this thread. lipska -- Lipska the Kat©: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun
[toc] | [prev] | [next] | [standalone]
| From | Joerg Meier <joergmmeier@arcor.de> |
|---|---|
| Date | 2013-05-04 14:49 +0200 |
| Message-ID | <1bx9g6rvlybbn.15ihvrdgc0pia$.dlg@40tude.net> |
| In reply to | #23818 |
On Sat, 04 May 2013 09:16:41 +0100, lipska the kat wrote: > On 04/05/13 05:01, qwertmonkey@syberianoutpost.ru wrote: >> What is wrong with this code? > Firstly, looking at this code gave me a headache :-( qwertmonkey has been told many times, but like Stefan Ram, he ignores all posts relating to his horrid coding style, and since people still help him, he probably just sees no need. Liebe Gruesse, Joerg -- Ich lese meine Emails nicht, replies to Email bleiben also leider ungelesen.
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2013-05-04 09:14 -0400 |
| Message-ID | <km31dk$n94$1@dont-email.me> |
| In reply to | #23821 |
On 5/4/2013 8:49 AM, Joerg Meier wrote:
> On Sat, 04 May 2013 09:16:41 +0100, lipska the kat wrote:
>
>> On 04/05/13 05:01, qwertmonkey@syberianoutpost.ru wrote:
>>> What is wrong with this code?
>> Firstly, looking at this code gave me a headache :-(
>
> qwertmonkey has been told many times, but like Stefan Ram, he ignores all
> posts relating to his horrid coding style, and since people still help him,
> he probably just sees no need.
What he may not know is that while some people help him,
others don't. I, for example, started to read his code but
found it so gratuitously ugly that after half a minute I said
"Ick" and quit. Whatever help he might have gotten from me
will forever remain a mystery, because I've got better things
to do. My eyebrows don't pluck themselves, you know.
--
Eric Sosman
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | Arved Sandstrom <asandstrom2@eastlink.ca> |
|---|---|
| Date | 2013-05-06 05:42 -0300 |
| Message-ID | <G1Kht.63661$2b6.7819@newsfe10.iad> |
| In reply to | #23822 |
On 05/04/2013 10:14 AM, Eric Sosman wrote: > On 5/4/2013 8:49 AM, Joerg Meier wrote: >> On Sat, 04 May 2013 09:16:41 +0100, lipska the kat wrote: >> >>> On 04/05/13 05:01, qwertmonkey@syberianoutpost.ru wrote: >>>> What is wrong with this code? >>> Firstly, looking at this code gave me a headache :-( >> >> qwertmonkey has been told many times, but like Stefan Ram, he ignores all >> posts relating to his horrid coding style, and since people still help >> him, >> he probably just sees no need. > > What he may not know is that while some people help him, > others don't. I, for example, started to read his code but > found it so gratuitously ugly that after half a minute I said > "Ick" and quit. Whatever help he might have gotten from me > will forever remain a mystery, because I've got better things > to do. My eyebrows don't pluck themselves, you know. > You lasted 30 seconds, Eric? :-) The first thing I do with a NG problem that involves code is very quickly scan it for readability, w/o even trying to understand the code proper. So whitespace, indentation, general naming etc. In this case I gave up in less than 10 seconds and read follow-ups to see if anyone actually tried to help. :-) AHS
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2013-05-04 21:31 -0400 |
| Message-ID | <5185b668$0$32110$14726298@news.sunsite.dk> |
| In reply to | #23821 |
On 5/4/2013 8:49 AM, Joerg Meier wrote: > On Sat, 04 May 2013 09:16:41 +0100, lipska the kat wrote: > >> On 04/05/13 05:01, qwertmonkey@syberianoutpost.ru wrote: >>> What is wrong with this code? >> Firstly, looking at this code gave me a headache :-( > > qwertmonkey has been told many times, but like Stefan Ram, he ignores all > posts relating to his horrid coding style, and since people still help him, > he probably just sees no need. I see some difference. This is coding C++ in Java. Both design and formatting. And this is pretty bad - as it almost always is to try and code X in Y. Stefans code is normal designed. The only problem is that it it gets formatted after the "Stefan Java coding convention", which deviate a lot from more standard Java coding conventions including the official one from SUN/Oracle. That is also a annoying, but not quite as much. (and I don't understand why he doesn't write the code in his style but 15 seconds before posting copy paste it over in a new doc, ask the IDE to reformat it and post the result) Arne
[toc] | [prev] | [next] | [standalone]
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Date | 2013-05-04 18:34 -0700 |
| Message-ID | <km4cou$g72$1@dont-email.me> |
| In reply to | #23831 |
On 5/4/2013 6:31 PM, Arne Vajhøj wrote: > (and I don't understand why he doesn't write the code > in his style but 15 seconds before posting copy paste > it over in a new doc, ask the IDE to reformat it and > post the result) I have two different coding styles that my editor (NetBeans) supports. One with more white space which is normal, and one with less white space for posting. It's easy to switch between them. (Well, currently I have to switch projects to do that, but that's not a burden usually.) I don't see why code can't be formatted for its intended audience either.
[toc] | [prev] | [next] | [standalone]
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Date | 2013-05-05 13:09 +0200 |
| Message-ID | <aumsvjFfo61U1@mid.individual.net> |
| In reply to | #23821 |
On 04.05.2013 14:49, Joerg Meier wrote: > On Sat, 04 May 2013 09:16:41 +0100, lipska the kat wrote: > >> On 04/05/13 05:01, qwertmonkey@syberianoutpost.ru wrote: >>> What is wrong with this code? >> Firstly, looking at this code gave me a headache :-( > > qwertmonkey has been told many times, but like Stefan Ram, he ignores all > posts relating to his horrid coding style, and since people still help him, > he probably just sees no need. What I find probably more annoying is his ripping apart of threads. With such high traffic as here it becomes quite tedious quickly to dig up all the branches of a single thread. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web