dinamic variables - help!!!!

W

whois

Hi!
I want to know if there is possible to read dinamicly variable or
functions in java? (in perl it's possible!)

I give an example:

i have one String variable e.g. x="small test";
create a second String named y="x";
now, when i print the variable 'y', i want that the result doesn't be
"x", but validate the result as another variable, and return "small
test".

this is a simple example, because i can use that concept to execute
functions...

thanks in advance.
 
P

Phillip Mills

this is a simple example, because i can use that concept to execute
functions...

The simplest way to do what you showed with strings in the example is
probably a HashMap, but if you really want dynamic functions, there's a
different way.

Reflection lets you look at a class and discover what it contains. Look
at methods such as Class.getMethod and Method.invoke.
 
M

Michael Borgwardt

Phillip said:
The simplest way to do what you showed with strings in the example is
probably a HashMap, but if you really want dynamic functions, there's a
different way.

Reflection lets you look at a class and discover what it contains. Look
at methods such as Class.getMethod and Method.invoke.

It should be mentioned that you almost certainly shouldn't *want* to be
doing this in the first place - a better design can usually avoid such
things.
 
P

Phillip Mills

Michael Borgwardt said:
It should be mentioned that you almost certainly shouldn't *want* to be
doing this in the first place - a better design can usually avoid such
things.

It has always bugged the hell out of me when people have responded to my
questions by trying to redefine my problem, so I try not to do it to
others. :)
 
T

Thomas Weidenfeller

Phillip said:
It has always bugged the hell out of me when people have responded to my
questions by trying to redefine my problem,

Because you didn't manage to describe it adequately?

Because you were about to do something utterly stupid?

If you need predictable (not reliable, predictable) answers, hire a
consultant and don't try newsgroups.

/Thomas
 
P

Phillip Mills

Thomas Weidenfeller said:
Because you didn't manage to describe it adequately?

When the question isn't understood, silence is always an acceptable
response.
Because you were about to do something utterly stupid?

Usually it's because there are people so full of themselves that they
feel obliged to act as know-it-alls. If they don't have the answer,
then it must be the fault of the question, right?

Or they have a particular agenda: "Tool X" is wonderful so let's change
the problem's parameters until "Tool X" becomes an appropriate solution.
(And heaven help the original poster if their question suggests that
"Tool X" isn't perfect!)

Or they just get cheap thrills out of implying that others are inferior.

It's true that sometimes people post questions based on strategies that
are full of holes, but to start by *assuming* that's the case strikes me
as rude and ignorant.
 
A

Andrew Thompson

When the question isn't understood, silence is always an acceptable
response.

So..
"I do not understand your vaguely defined
question on points 2,3 and 7. Clarify those
and I will give you the best answer."
...is *not* an acceptable response?

You sound like you are saying
"Tell me what I want to hear or be silent."

That seems to fit the 'hire a consultant'
solution that Thomas was referring to..
You will not get that crap here, fortunately.
 
R

Roedy Green

Because you didn't manage to describe it adequately?

Because you were about to do something utterly stupid?

If you need predictable (not reliable, predictable) answers, hire a
consultant and don't try newsgroups.

It is a matter of gift horses. People offer what they can. Often a
problem falls apart easily if you simply redefine the problem, backing
up a bit to think about the final desired result and not getting too
hung up on HOW you get there.

If you are too rude about the unwanted gift horses, you stop getting
any gift horses.

Think of the newsgroups as ongoing free brainstorming sessions. You
don't want to throw cold water to discourage the flow of new ideas.
 
R

Roedy Green

It's true that sometimes people post questions based on strategies that
are full of holes, but to start by *assuming* that's the case strikes me
as rude and ignorant.

Most of the people asking questions ARE newbies, or they are well
known regulars. It means nothing about you that you are presumed a
newbie when you are simply new to the group.

On the other hand you exude entitlement which many find even more
irritating than arrogance. Nobody OWES you any answer at all, much
less one in the form you desire.

If someone makes any stab at answering your question, they are trying
to be as helpful as they can. The alternative would be to hold back
the little info they can and leave you in the dark. If even there is a
10% chance the answer could prove useful, I'd think you would feel
grateful they tool the time to share that information. Most people
ignored you entirely.

If you want to control the way people answer you, you will have to pay
them.
 
P

Phillip Mills

Andrew Thompson said:
So..
"I do not understand your vaguely defined
question on points 2,3 and 7. Clarify those
and I will give you the best answer."
..is *not* an acceptable response?

Of course it would be acceptable. Where did I say that silence was the
*only* acceptable answer?

What I consider unacceptable is, "Only an idiot would put themselves in
a position where that question was necessary, so -- without knowing a
thing about your project -- here's what you should be asking instead."
 
P

Phillip Mills

Roedy Green said:
On the other hand you exude entitlement which many find even more
irritating than arrogance. Nobody OWES you any answer at all, much
less one in the form you desire.

I have seen people who try to insist on receiving an answer from a
newsgroup and who become irate when no one answers their (often
off-topic) question. I don't do that and since I specifically said,
"silence is always an acceptable response," I don't get where your
'entitlement' insult is coming from. How about you wait until I ask
something before judging whether I show enough gratitude for responses?
If someone makes any stab at answering your question, they are trying
to be as helpful as they can. The alternative would be to hold back
the little info they can and leave you in the dark. If even there is a
10% chance the answer could prove useful, I'd think you would feel
grateful they tool the time to share that information. Most people
ignored you entirely.

I agree with that paragraph completely.

I have no problem with partial answers, tentative answers, RTFM answers,
wrong answers, or no answers. I do have a problem with those who
dismiss questions as meaningless, irrelevant, stupid, or not legitimate
so that they can demonstrate their own shining excellence.
If you want to control the way people answer you, you will have to pay
them.

(Actually, paying people for expertise and then trying to control how
they answer your questions is a good recipe for wasting money. OTOH, if
they try to redefine your business without understanding it....)
 
R

Roedy Green

I do have a problem with those who
dismiss questions as meaningless, irrelevant, stupid, or not legitimate
so that they can demonstrate their own shining excellence.

That is reasonable. But what it sounded originally like you were
saying is that people have no business trying to redefine your
problem.

You were treating those sorts of answers as insults rather than
unwanted gift horses.

The problem is you have to accept the chaff with the wheat. Even
arrogant assholes can be useful if you can ignore the packaging.

There are a multitude of reasons people are willing to help you for
free.

They may be religious (see http://mindprod.com/ccism.html for mine),
to feel helpful or worthy, to gain admiration, to scare up business,
to find people to insult who can't hit back, pathological curiosity,
procrastination, checking out information -- knowing others will shoot
it down if it is wrong.

The point to always remember is that you have no entitlement of any
kind to an answer, much less in the form you want. EVERYTHING you get
is a free bonus. Ever see the movie Brother Sun and Sister Moon? when
St. Francis of Assisi thanks people for throwing garbage on him -- he
needs the food. That's a bit like what happens when you ask a question
in a newsgroup.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top