Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cannot find symbol?

128 views
Skip to first unread message

qwert...@syberianoutpost.ru

unread,
May 4, 2013, 12:01:44 AM5/4/13
to
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());
}
}
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

Daniel Pitts

unread,
May 4, 2013, 12:54:02 AM5/4/13
to
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.

lipska the kat

unread,
May 4, 2013, 4:16:41 AM5/4/13
to
On 04/05/13 05:01, qwert...@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

qwert...@syberianoutpost.ru

unread,
May 4, 2013, 6:50:39 AM5/4/13
to
> Try reducing your problem to an SSCCE <http://sscce.org> ...
~
Sorry! The thing is that I wasn't sure what was causing the problem and I did
attempt to reduce that code to an SSCCE.
~
The original code is based on reflection
~
> This looks like it was copied from C++ code which was copied from C code.
~
You would make a good detective ;-)
~
> ((IADObj) tCtxt).setCtxt((new Integer(aSAr[0])).intValue(), aSAr[1], (new Long(aSAr[0])).longValue());
~
The whole purpose of doing things this way is not using a cast within verifyCtxt,
where using the strategy pattern an object of a certain class (which is given via
input parameter (.verifyCtxt(aSAr, _.getClass()))) is created
~
I am trying to do everything within DTO_T_Ctxt06 through templates, so, users
don't have to code this class and for reasons I still don't get I am not able
to get this right
~
Say, a user goes:

// __
class Ho3K{
private String aS;
Ho3K(){}
public void setCtxt(String aS){ this.aS = aS; }
public String toString(){ return(" aS: |" + aS + "|"); }
}
~
...
Ho3K Ho3 = new Ho3K();

aSAr = new String[]{"ho, ho, ho!"};

DTO_T_Ctxt06<Ho3K> Ho3Ctxt = new DTO_T_Ctxt06<Ho3K>();

Ho3Ctxt.verifyCtxt(aSAr, Ho3.getClass());
System.err.println("// __ Ho3.getCtxtDTO() : |" + Ho3.getCtxtDTO() + "|");
~
How do you do such a thing?
~
lbrtchx

markspace

unread,
May 4, 2013, 8:43:19 AM5/4/13
to
On 5/4/2013 3:50 AM, qwert...@syberianoutpost.ru wrote:
> class Ho3K{
> private String aS;
> Ho3K(){}
> public void setCtxt(String aS){ this.aS = aS; }
> public String toString(){ return(" aS: |" + aS + "|"); }

> System.err.println("// __ Ho3.getCtxtDTO() : |" + Ho3.getCtxtDTO() + "|");

> How do you do such a thing?

What is "such a thing?" What are you even *trying* to do? You can't
call "getCtxtDTO" on an object that only defines the methods "setCtxt"
and "toString".


Joerg Meier

unread,
May 4, 2013, 8:49:06 AM5/4/13
to
On Sat, 04 May 2013 09:16:41 +0100, lipska the kat wrote:

> On 04/05/13 05:01, qwert...@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.

Eric Sosman

unread,
May 4, 2013, 9:14:40 AM5/4/13
to
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, qwert...@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
eso...@comcast-dot-net.invalid

qwert...@syberianoutpost.ru

unread,
May 4, 2013, 9:51:23 AM5/4/13
to
>> class Ho3K{
>> private String aS;
>> Ho3K(){}
>> public void setCtxt(String aS){ this.aS = aS; }
>> public String toString(){ return(" aS: |" + aS + "|"); }
>> System.err.println("// __ Ho3.getCtxtDTO() : |" + Ho3.getCtxtDTO() + "|");
>> How do you do such a thing?
~
>What is "such a thing?" What are you even *trying* to do? You can't
>call "getCtxtDTO" on an object that only defines the methods "setCtxt"
>and "toString".
~
my mistake. I (quickly and wrongly) replaced some of the text while editing my
own post
~
Take a look at my initial posting. DTO_T_Ctxt06 and Ho3K are just mock objects
created in method "verifyCtxt" in class DTO_T_Ctxt, which I get as Data Transfer
Objects
~
> 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.
~
Joerg I usually don't talk to politicians/people with "political" qualms,
specially if they, not only assume some evil intention in your ways, but talk
from a "Godly" prescribing point of view, defending/standing for "we the people"
~
It may relate to the fact that I am a teacher (so I am conditioned to be
lenient about people's ways) and researcher myself in consciousness studies/
neurobiology: I don't think that everyone should be right-handed or act and
"think" in a certain ways even if "the majority" does
~
I have read and worked on -really- badly worded, formatted code. At the
end of the day it is primarily "on the eyes of the compiler" determining what is
kosher or not to itself
~
Haven't you heard the joke about how an engineer a physicist and a mathematician
fight a fire?
~
For example, unnecessary noises bother the hell out of me, but when I notice,
say, a woman (and they love those kinds of things!) walking on a wooden floor
with really noisy hard sole high heels. I keep my annoyance within myself and
don't extrapolate my own thinking into believing they are evil or the alignment
of stars in heaven will be altered because of that, nor would I disrespect or
mistreat them in any way
~
> What he may not know is that while some people help him, others don't.
~
... the bad part about that being?
~
This is a fact of life regarding all matters and ultimately you do get at
things -your- way. In fact, I see the good in "politicians" not liking "me"
~
lbrtchx

Daniel Pitts

unread,
May 4, 2013, 12:43:04 PM5/4/13
to
On 5/4/13 6:51 AM, qwert...@syberianoutpost.ru wrote:
>>> class Ho3K{
>>> private String aS;
>>> Ho3K(){}
>>> public void setCtxt(String aS){ this.aS = aS; }
>>> public String toString(){ return(" aS: |" + aS + "|"); }
>>> System.err.println("// __ Ho3.getCtxtDTO() : |" + Ho3.getCtxtDTO() + "|");
>>> How do you do such a thing?
> ~
>> What is "such a thing?" What are you even *trying* to do? You can't
>> call "getCtxtDTO" on an object that only defines the methods "setCtxt"
>> and "toString".
> ~
> my mistake. I (quickly and wrongly) replaced some of the text while editing my
> own post
> ~
> Take a look at my initial posting. DTO_T_Ctxt06 and Ho3K are just mock objects
> created in method "verifyCtxt" in class DTO_T_Ctxt, which I get as Data Transfer
> Objects

I posted the solution. Use interfaces. There are no such things as C++
style templates in Java. You need to use interfaces. Is there a reason
my solution isn't acceptable to you?

> ~
>> 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.
> ~
> Joerg I usually don't talk to politicians/people with "political" qualms,
> specially if they, not only assume some evil intention in your ways, but talk
> from a "Godly" prescribing point of view, defending/standing for "we the people"
> ~
> It may relate to the fact that I am a teacher (so I am conditioned to be
> lenient about people's ways) and researcher myself in consciousness studies/
> neurobiology: I don't think that everyone should be right-handed or act and
> "think" in a certain ways even if "the majority" does
> ~
> I have read and worked on -really- badly worded, formatted code. At the
> end of the day it is primarily "on the eyes of the compiler" determining what is
> kosher or not to itself
Not entirely. It is primarily the eyes of colleagues which need to
modify the behavior of the code. The compiler, while less forgiving for
syntax, is completely forgiving of semantics. Humans are the opposite,
and in fact that is the trait which we need. The syntax of a program can
interfere with understanding the semantics of it. This is why you find
less help. Why do you ignore the help you do get?
> ~
> Haven't you heard the joke about how an engineer a physicist and a mathematician
> fight a fire?
No, I haven't.
> ~
> For example, unnecessary noises bother the hell out of me, but when I notice,
> say, a woman (and they love those kinds of things!) walking on a wooden floor
> with really noisy hard sole high heels. I keep my annoyance within myself and
> don't extrapolate my own thinking into believing they are evil or the alignment
> of stars in heaven will be altered because of that, nor would I disrespect or
> mistreat them in any way
I would imagine you invite them over less often than you do less noisy
women.
> ~
>> What he may not know is that while some people help him, others don't.
> ~
> ... the bad part about that being?
Higher noise to signal ratio for your answers.
> ~
> This is a fact of life regarding all matters and ultimately you do get at
> things -your- way. In fact, I see the good in "politicians" not liking "me"

There is a difference between politics and social acceptability. As a
hiring manager, if you presented this code to me, I would not hire you.
If somehow you got hired where I worked and I saw you made this code,
I would do whatever I could to get you fired. This code costs at least
10 times as much as any more conventional equivalent.

I would do this regardless of the type of job you were hired to do.
Research, enterprise, embedded, teaching. Especially teaching. It would
not be a personal judgement against you, but a value judgement against
what you contribute.

On an unrelated note, it would be more polite of you to follow standard
usenet protocol for replying to messages. Keeping the thread in one
place makes it easier for me to follow along. However you reply now, it
splits the thread into multiple. Maybe you need a different news reader.


lipska the kat

unread,
May 4, 2013, 1:29:02 PM5/4/13
to
On 04/05/13 14:51, qwert...@syberianoutpost.ru wrote:
>>> class Ho3K{
>>> private String aS;
>>> Ho3K(){}
>>> public void setCtxt(String aS){ this.aS = aS; }
>>> public String toString(){ return(" aS: |" + aS + "|"); }
>>> System.err.println("// __ Ho3.getCtxtDTO() : |" + Ho3.getCtxtDTO() + "|");
>>> How do you do such a thing?

Someone has suggested you use interfaces to achieve your goals.
Here is an example of Strategy pattern in Java. You need to scroll down
a bit to see the Java code.

http://en.wikipedia.org/wiki/Strategy_pattern

No generics, just interfaces, if this approach is unsuitable perhaps you
could tell us why, I'm intrigued as to what *exactly* you are trying to do.

qwert...@syberianoutpost.ru

unread,
May 4, 2013, 4:58:38 PM5/4/13
to
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[i] + "|");
}
// __
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 + "|");
// __
}
}

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Message has been deleted
Message has been deleted

markspace

unread,
May 4, 2013, 8:53:39 PM5/4/13
to
On 5/4/2013 1:58 PM, qwert...@syberianoutpost.ru 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.




Daniel Pitts

unread,
May 4, 2013, 9:07:56 PM5/4/13
to
On 5/4/13 1:58 PM, qwert...@syberianoutpost.ru 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.

Arne Vajhøj

unread,
May 4, 2013, 9:31:19 PM5/4/13
to
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, qwert...@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


markspace

unread,
May 4, 2013, 9:34:37 PM5/4/13
to
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.


Arne Vajhøj

unread,
May 4, 2013, 9:44:09 PM5/4/13
to
On 5/4/2013 9:51 AM, qwert...@syberianoutpost.ru wrote:
>> 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.
> ~
> Joerg I usually don't talk to politicians/people with "political" qualms,
> specially if they, not only assume some evil intention in your ways, but talk
> from a "Godly" prescribing point of view, defending/standing for "we the people"
> ~
> It may relate to the fact that I am a teacher (so I am conditioned to be
> lenient about people's ways) and researcher myself in consciousness studies/
> neurobiology: I don't think that everyone should be right-handed or act and
> "think" in a certain ways even if "the majority" does

You are missing the point.

There is not one coding style that is better than all other.

But there are huge objective benefits of everybody using the same
or at least very similar coding style.

It is simple faster to read and understand code in a familiar coding
style.

So a better analogy is that:
- everybody driving at right side of the road or everybody driving at
the left side of the road are equally good
- both are a lot better than some driving at right side of the road and
some driving at the left side of the road

So either convince a few million Java developers to follow your style
or bite the bullet and use their style.

> I have read and worked on -really- badly worded, formatted code. At the
> end of the day it is primarily "on the eyes of the compiler" determining what is
> kosher or not to itself

No no no.

Not all code that work are equally good.

Ease of maintenance is a primary goal in creating software.

> For example, unnecessary noises bother the hell out of me, but when I notice,
> say, a woman (and they love those kinds of things!) walking on a wooden floor
> with really noisy hard sole high heels. I keep my annoyance within myself and
> don't extrapolate my own thinking into believing they are evil or the alignment
> of stars in heaven will be altered because of that, nor would I disrespect or
> mistreat them in any way

But you may (and you should) consider her less suited for a job where
making little noise is necessary.

Arne





Arne Vajhøj

unread,
May 4, 2013, 9:47:13 PM5/4/13
to
On 5/4/2013 9:51 AM, qwert...@syberianoutpost.ru wrote:
> For example, unnecessary noises bother the hell out of me, but when I notice,
> say, a woman (and they love those kinds of things!) walking on a wooden floor
> with really noisy hard sole high heels. I keep my annoyance within myself and
> don't extrapolate my own thinking into believing they are evil or the alignment
> of stars in heaven will be altered because of that, nor would I disrespect or
> mistreat them in any way

And besides in this context I would argue that it is you that are
being impolite.

You want people to spend time for free on helping them with your
problem, but you don't want to spend the time making it easy
for them by making the code (and the post in general) easy to
read.

That is pretty rude behavior.

Arne

qwert...@syberianoutpost.ru

unread,
May 5, 2013, 4:26:29 AM5/5/13
to
> You no longer have to deal with Class tokens, instantiation, exceptions,
or generics! ...
~
> 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.
~
> What are you even *trying* to do?
~
Daniel et al, the reason why I chose to use Class tokens, instantiation and
generics instead of interfaces is because:
~
1) this code takes command line arguments (which are all text/of type String)
and returns an (I was hoping for, typed) object with marshalled and addressable
data
~
2) I don't want for users to have to write an interface for each set of
command line arguments
~
3) Since each type of program produces a distinctive type of object based on 1)
a DTO is all you need as an output, which (IMO) is all the user should be
required to handle
~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~
Now, in defense of "women walking on wearing really noisy hard sole
high heels" ...
~
>> For example, unnecessary noises bother the hell out of me ...
> But you may (and you should) consider her less suited ...
> I would imagine you invite them over less often than you do less noisy women.
~
Once, in a totally serendipitous way, I met a girl from Hungary, who was a
gardener, knew what semiotics is, had been raised (in Germany as) a Franciscan,
... (you definitely know sh!t when you trade on it!) To me she was some
Kantian-like "that sh!t an sich" ... but she smoked (which was severely
contradictory) ...
~
>> Haven't you heard the joke about how an engineer a physicist and a
mathematician
>> fight a fire?
> No, I haven't.
~
A critical room in a crowded building gets in whipping fire:
~
engineer: sets off all alarms in the building, calls fire department/emergency,
makes his way into the room, starts using all kinds of fire extinguishers, makes
huge mess and keeps frantically screaming from a balcony even after
extinguishing the fire
~
physicist: assesses the situation, asks a nurse (after clearly showing it to
her) to find the right kind of fire extinguishers and stand by with more of
them, tells her to tightly seal crack between the door and the frame with wet
clothing after he gets in and to open the door to get him out if he doesn't
knock from the inside every time after 30 seconds, puts on a wet mask, gets
in trying to remain the least excited he possibly could, from a distance uses
the right extinguisher creating the least possible mess and once done quietly
offers to clean up the mess himself ... no one else finds out what had just
happened ...
~
mathematician: notices the ensuing fire, sees fire extinguisher, ... and walks
away because "that problem had a solution"
~
> The syntax of a program can interfere with understanding the semantics of it.
~
"semantics" you say? it amazes me how we tech monkeys freely mess with concepts
such as "semantics", "information", "abstract" and how we apparently think of
coding (essentially some textual carpentry) as if it were high-end philosophy
of some sort
~
> There is a difference between politics and social acceptability.
> I would do whatever I could to get you fired.
> I would do this regardless of the type of job you were hired to do.
~
yes, there is, but that difference is voided when "socially acceptable" people
start seeing themselves as "the ones" and those who aren't as evildoers
~
My mind might be somehow so exceptionally good at visually parsing out what
should matter from what doesn't that I even find annoying that people waste
time talking about such cr@p and/or it may relate to me being downright
lenient when it comes to people's ways
~
> Research, enterprise, embedded, teaching. Especially teaching.
~
I may see your point somewhat with the former cases, but when it comes to
teaching I can tell you that the job of a teacher is not "norming" people
and/or putting their minds in straight jackets "for 'the greater good'"
~
> On an unrelated note, it would be more polite of you to follow standard
> usenet protocol for replying to messages. Keeping the thread in one
> place
~
I use some java code based on apache commons NetComponents and I haven't figure
out how to troubleshoot that (nor have they let me know) it sometimes works

http://mail-archives.apache.org/mod_mbox/commons-user/201209.mbox/date

Albretch Mueller SimpleNNTPHdr HeaderFields ...
~
> So a better analogy is that (of everybody driving on the same side of the road) ...
~
your analogy is quite a bit forceful. I myself find the left-handed people one
more appropriate
~
> Ease of maintenance is a primary goal in creating software.
~
I find often arguments about those (to me silly) issues. To me it is a totally
technical problem people should not even have to talk about. I wonder why people
maintaining software themselves haven't design software as part of the software
dev cycles to
~
1) convert/parse code from java classes (and/or source) into XML
~
2) turn the XML using XSLT into "company/socially acceptable/SSCCE/maintenance
friendly" code
~
3) there may be certain things a bit hard to code for out. GUI would be a nice
aid
~
4) keep users/finger profiles
~
5) keep the whole thing as a company-wide corpus
~
> You want people to spend time ...
~
Again, I wonder what makes you think that I want for "people" to waste their
time trying to help me. If -YOU- don't want to because of whatever reason, you,
very naturally and effortlessly indeed, can ignore it and that will be that
~
Yes, I have coded quite a bit of FORTRAN, ANSI C, ANSI C++ and lately java and
I even have a hard time keeping apart the three languages that I speak. I will
however be a little more conscious of how harmful/upsetting to the coding style
inquisition my coding is once I make it public
~
Also, IMO, we tech monkeys should once if a while take our heads out of our own
read ends for some fresh breathing. I (almost compulsively in an "unconscious"
way) try to help people, even offering money to (whom I believe to be) single
mothers struggling to pay for groceries, who sometimes even freak out when they
notice a stranger handing cash to them. I don't tell them they should or
shouldn't have done this or that, I just feel like I am helping my own single
mother
~
lbrtchx

lipska the kat

unread,
May 5, 2013, 6:34:12 AM5/5/13
to
On 05/05/13 09:26, qwert...@syberianoutpost.ru wrote:
>> You no longer have to deal with Class tokens, instantiation, exceptions,
> or generics! ...
> ~
>> 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.
> ~
>> What are you even *trying* to do?
> ~
> Daniel et al, the reason why I chose to use Class tokens, instantiation and
> generics instead of interfaces is because:
> ~
> 1) this code takes command line arguments (which are all text/of type String)
> and returns an (I was hoping for, typed) object with marshalled and addressable
> data
> ~
> 2) I don't want for users to have to write an interface for each set of
> command line arguments

[snip]

What is the possible set of command line args?
Can the arg count change per invocation?
AFAIAA a main program can't 'return' anything, when it returns it's
finished. How do you see your users using your application?

Robert Klemme

unread,
May 5, 2013, 7:09:29 AM5/5/13
to
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, qwert...@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/

Daniel Pitts

unread,
May 5, 2013, 11:48:17 AM5/5/13
to
On 5/5/13 1:26 AM, qwert...@syberianoutpost.ru wrote:
>> You no longer have to deal with Class tokens, instantiation, exceptions,
> or generics! ...
> ~
>> 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.
> ~
>> What are you even *trying* to do?
> ~
> Daniel et al, the reason why I chose to use Class tokens, instantiation and
> generics instead of interfaces is because:
> ~
> 1) this code takes command line arguments (which are all text/of type String)
> and returns an (I was hoping for, typed) object with marshalled and addressable
> data
> ~
> 2) I don't want for users to have to write an interface for each set of
> command line arguments

Then how does the code know how to parse the command line? You have in
there hard-coded int, String, and long processing. If the parsing is
different, how do you intend on specifying that?

Anyway, it sounds like you want to dynamically call a method. You don't
really need generics for that, you need reflection. See
Class.getMethods(...) and Method.invoke(...).

Do be aware that you can be too smart for your own good when dealing
with Reflection. It is a jet-powered swiss-army chain-saw. It can
solve a lot of problems, but it is no small feat of engineering to do
so. If a bug is uncovered in reflective code, it will likely take longer
to fix it than it would have taken to simplify the code not to use
reflection in the first case.

I should know, because I've done it both ways. I will say however, I
didn't have to ask usenet why my code wasn't working, because I actually
read the specs. I suggest you read up on both Reflection and Generics
(and why they don't always play nice with each other).

>> The syntax of a program can interfere with understanding the semantics of it.
> ~
> "semantics" you say? it amazes me how we tech monkeys freely mess with concepts
> such as "semantics", "information", "abstract" and how we apparently think of
> coding (essentially some textual carpentry) as if it were high-end philosophy
> of some sort
That's the difference between an engineer and a programmer. An engineer
can see the meaning and intention of a design. A programmer merely sees
a set of instructions for the processor to carry out. Programmers do
fine on small bits of software, but an engineer is required to make a
lasting system. Data is just data until its interpreted. That
interpretation is what gives it semantics. Code is also just data. The
compiler doesn't care whether your semantics are correct, it just
faithfully translates what it can into machine code, and the CPU just
faithfully executes what it can of that code.

A human on the other hand, knows *why* the code is the way that it is,
and what the goal of the code is. A human understands the meaning of the
input data, and the meaning of the output data.

> ~
>> There is a difference between politics and social acceptability.
>> I would do whatever I could to get you fired.
>> I would do this regardless of the type of job you were hired to do.
> ~
> yes, there is, but that difference is voided when "socially acceptable" people
> start seeing themselves as "the ones" and those who aren't as evildoers
> ~
> My mind might be somehow so exceptionally good at visually parsing out what
> should matter from what doesn't that I even find annoying that people waste
> time talking about such cr@p and/or it may relate to me being downright
> lenient when it comes to people's ways
> ~
>> Research, enterprise, embedded, teaching. Especially teaching.
> ~
> I may see your point somewhat with the former cases, but when it comes to
> teaching I can tell you that the job of a teacher is not "norming" people
> and/or putting their minds in straight jackets "for 'the greater good'"
No, but at the same time, a teacher should at least understand the norm,
and the argument for and against it. I am personally someone who has
gone against the norm for much of my career. With much success, I might
add. The difference is that I could justify why the norm wasn't working
for the case.

Can you justify your naming convention over the Java communities coding
convention? If you had a decent justification, I might just switch to
yours.
> ~
>> On an unrelated note, it would be more polite of you to follow standard
>> usenet protocol for replying to messages. Keeping the thread in one
>> place
> ~
> I use some java code based on apache commons NetComponents and I haven't figure
> out how to troubleshoot that (nor have they let me know) it sometimes works
>
> http://mail-archives.apache.org/mod_mbox/commons-user/201209.mbox/date
>
> Albretch Mueller SimpleNNTPHdr HeaderFields ...
> ~
>> So a better analogy is that (of everybody driving on the same side of the road) ...
> ~
> your analogy is quite a bit forceful. I myself find the left-handed people one
> more appropriate
> ~
>> Ease of maintenance is a primary goal in creating software.
> ~
> I find often arguments about those (to me silly) issues. To me it is a totally
> technical problem people should not even have to talk about. I wonder why people
> maintaining software themselves haven't design software as part of the software
> dev cycles to
> ~
> 1) convert/parse code from java classes (and/or source) into XML
Why XML? You've simply traded one syntax for another. It's symbol
names, comment, and examples that help humans comprehend the meaning,
not (just) structure and syntax.

> ~
> 2) turn the XML using XSLT into "company/socially acceptable/SSCCE/maintenance
> friendly" code
Would that XSLT translate "DTO_T_Ctxt" into an understandable token?

> ~
> 3) there may be certain things a bit hard to code for out. GUI would be a nice
> aid
I'm not sure what you mean by this.

> ~
> 4) keep users/finger profiles
Most VCS's do this, or at least part of this.
> ~
> 5) keep the whole thing as a company-wide corpus
See my reply to 4.
> ~
>> You want people to spend time ...
> ~
> Again, I wonder what makes you think that I want for "people" to waste their
> time trying to help me. If -YOU- don't want to because of whatever reason, you,
> very naturally and effortlessly indeed, can ignore it and that will be that
> ~
> Yes, I have coded quite a bit of FORTRAN, ANSI C, ANSI C++ and lately java and
> I even have a hard time keeping apart the three languages that I speak. I will
> however be a little more conscious of how harmful/upsetting to the coding style
> inquisition my coding is once I make it public
> ~
> Also, IMO, we tech monkeys should once if a while take our heads out of our own
> read ends for some fresh breathing. I (almost compulsively in an "unconscious"
> way) try to help people, even offering money to (whom I believe to be) single
> mothers struggling to pay for groceries, who sometimes even freak out when they
> notice a stranger handing cash to them. I don't tell them they should or
> shouldn't have done this or that, I just feel like I am helping my own single
> mother

On the other hand, if a single mother came to you, told you she was
hungry and needed money for drugs, you'd probably feel somewhat
compelled to explain that drugs won't fix her hunger.

qwert...@syberianoutpost.ru

unread,
May 5, 2013, 7:15:39 PM5/5/13
to
> What is the possible set of command line args?
~
Any kind (of Unix-like) command line argument a java program would use at
start up
~
> Can the arg count change per invocation?
~
For invocations -relating to a different code base-, yes. Not only the count,
but the type as well. We talked already to some extent about what I had in mind
here:
~
comp.lang.java.programmer: regexp(ing) Backus-Naurish expressions ...
~
The reason why I went for this generics + reflection kind of juggling, is
because I just want for the user to define the object using a 0-argument ctor
and then code herself the sanity checks, marshalling and conditions in the
"set context" (setCtxt) method instead of using Constructor.newInstance(),
because I am avoiding having to deal with specific getDeclaredField(...),
setAccessible(...) conditioning cases inside of that code
~
Again, I went monkey because I am still not 100% clear about how to make
generics and reflection dance well together in such cases. That code as it is
works just fine for now. I may have to refactor/improve it in another iteration
~
> AFAIAA a main program can't 'return' anything, when it returns it's
> finished. How do you see your users using your application?
~
That was just some "proof-of-concept" example. Of course, you can use it outside
of a static context
~
> What I find probably more annoying is his ripping apart of threads.
~
Again, as I explained I post usenet messages using some java code, which seems
not to keep replies within the same threads. How do you post your comments? WHich
library do you use?
~
> Then how does the code know how to parse the command line?
~
That part of the code was straightforward. I just had my doubts about the
declarative DTO creation part
~
> Why XML? You've simply traded one syntax for another.
~
not exactly. XML is very easy when it comes to interchanging and addressing; say:
~
* you are coding and instead of having some auto complete based on the API you
want to refer it to the company code base
~
* you would keep all the code base in an XML dababase and code triggers to
alert when some code seems to be a good candidate for refactoring based on
some metrics ...
~
> It's symbol
> names, comment, and examples that help humans comprehend the meaning,
> not (just) structure and syntax.
~
for symbol names, comment, and examples, since they would be other
kinds of data, separate korpora should be used. Of course, with some
pointers among all corpora to establish concordance
~
> > 2) turn the XML using XSLT into "company/socially acceptable/SSCCE/maintenance
> > friendly" code
> Would that XSLT translate "DTO_T_Ctxt" into an understandable token?
~
If the big wigs so chose. The best thing about it is you wouldn't care, nor would
you waste time trying to norm people and politicizing. philosophizing about it
~
> > 3) there may be certain things a bit hard to code for out. GUI would be a nice
> > aid
~
> I'm not sure what you mean by this.
~
People like movies, you know, so they like to "see something". Say you have clients
with some RFEs and you map the texts relating to previous specs (everything must be
in corpora) to the verbal descriptions of what they want, from there to the code ...
~
> On the other hand, if a single mother came to you, told you she was
> hungry and needed money for drugs, you'd probably feel somewhat
> compelled to explain that drugs won't fix her hunger.
~
I meant single mothers in a cashier line noticing the math doesn't work in their favor
~
There is more than code and algorithms out there in real like
~
lbrtchx

Arved Sandstrom

unread,
May 6, 2013, 4:42:14 AM5/6/13
to
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

Lew

unread,
May 6, 2013, 4:12:35 PM5/6/13
to
On Saturday, May 4, 2013 6:51:23 AM UTC-7, qwert...@syberianoutpost.ru wrote:

Please do not omit attributions, monkey.

[ Joerg Meier wrote: ]
>> 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.

> Joerg I usually don't talk to politicians/people with "political" qualms,

What does that have to do with anything?

> specially if they, not only assume some evil intention in your ways, but talk

Again, relevance?

> from a "Godly" prescribing point of view, defending/standing for "we the people"

You've been advised about widespread and widely-adopted conventions.
Why the piss-ant attitude?

> It may relate to the fact that I am a teacher (so I am conditioned to be

Must be a real winner of a teacher with that attitude.

> lenient about people's ways) and researcher myself in consciousness studies/
> neurobiology: I don't think that everyone should be right-handed or act and
> "think" in a certain ways even if "the majority" does

Again, how is that relevant? Society has conventions. You, apparently, are sociopathic.

> I have read and worked on -really- badly worded, formatted code. At the
> end of the day it is primarily "on the eyes of the compiler" determining what is
> kosher or not to itself

You are writing to *people* for help. If the compiler sufficed, you'd not need to post here.

> This is a fact of life regarding all matters and ultimately you do get at
> things -your- way. In fact, I see the good in "politicians" not liking "me"

You are just wasting people's time.

--
Lew

Arne Vajhøj

unread,
May 6, 2013, 9:52:03 PM5/6/13
to
On 5/6/2013 4:12 PM, Lew wrote:
> On Saturday, May 4, 2013 6:51:23 AM UTC-7, qwert...@syberianoutpost.ru wrote:
>> lenient about people's ways) and researcher myself in consciousness studies/
>> neurobiology: I don't think that everyone should be right-handed or act and
>> "think" in a certain ways even if "the majority" does
>
> Again, how is that relevant? Society has conventions. You, apparently, are sociopathic.

Maybe it is time to enjoy the good spring weather?!?!

Arne


0 new messages