reflect field  
Author Message
ZaRMaS





PostPosted: 2006-12-21 18:26:00 Top

java-programmer, reflect field Hi all,

I want to get value of string variable in a class, and field it with
new strings like this :

EXample

public class helloWold()
{
String myString1 = "test1";
String myString2 = "test2";
String myString3 = "test3";
String myString4 = "test4";
}


public static void main(String[] args) {
Field myField[] = helloWold().class.getFields();

for (int i = 0; i < myField.length; i++)
{
System.out.println(myField[i].getName()); //get value
}
}

Actually I get the value, but i didn't know how to field it. I try the
method set but i have an error
'an not set java.lang.String field to java.lang.String'

Any ideas

Thanks.

Merci d avoir lu et de vos idees par avance

 
wesley.hall





PostPosted: 2006-12-21 19:04:00 Top

java-programmer >> reflect field
email***@***.com wrote:
> Hi all,
>
> I want to get value of string variable in a class, and field it with
> new strings like this :
>
> EXample
>
> public class helloWold()
> {
> String myString1 = "test1";
> String myString2 = "test2";
> String myString3 = "test3";
> String myString4 = "test4";
> }
>
>
> public static void main(String[] args) {
> Field myField[] = helloWold().class.getFields();
>
> for (int i = 0; i < myField.length; i++)
> {
> System.out.println(myField[i].getName()); //get value
> }
> }
>
> Actually I get the value, but i didn't know how to field it. I try the
> method set but i have an error
> 'an not set java.lang.String field to java.lang.String'
>
> Any ideas

You know, it amazes me how many people post in this group asking for
help and say something like...

"I wrote this code (which I have posted), it works.... but some other
code (which I haven't posted) doesn't work. Please help!".

I am starting to understand why Andrew Thompson is always grumpy ;)

 
Phi





PostPosted: 2006-12-21 20:58:00 Top

java-programmer >> reflect field email***@***.com wrote:
> email***@***.com wrote:
>> Hi all,
>>
>> I want to get value of string variable in a class, and field it with
>> new strings like this :
>>
>> EXample
>>
>> public class helloWold()
>> {
>> String myString1 = "test1";
>> String myString2 = "test2";
>> String myString3 = "test3";
>> String myString4 = "test4";
>> }
>>
>>
>> public static void main(String[] args) {
>> Field myField[] = helloWold().class.getFields();
>>
>> for (int i = 0; i < myField.length; i++)
>> {
>> System.out.println(myField[i].getName()); //get value
>> }
>> }
>>
>> Actually I get the value, but i didn't know how to field it. I try the
>> method set but i have an error
>> 'an not set java.lang.String field to java.lang.String'
>>
>> Any ideas
>
> You know, it amazes me how many people post in this group asking for
> help and say something like...
>
> "I wrote this code (which I have posted), it works.... but some other
> code (which I haven't posted) doesn't work. Please help!".
>
> I am starting to understand why Andrew Thompson is always grumpy ;)
>
I just had a closer look at java reflection and java.beans. I probably
could help you, but I need some more input:

What do you mean with "how to field it"?
And what do you mean with a "method set": Your code returns a Field-Set
and not a Method-Set.

phi
 
 
Lew





PostPosted: 2006-12-21 23:25:00 Top

java-programmer >> reflect field email***@***.com wrote:
> You know, it amazes me how many people post in this group asking for
> help and say something like...
>
> "I wrote this code (which I have posted), it works.... but some other
> code (which I haven't posted) doesn't work. Please help!".
>
> I am starting to understand why Andrew Thompson is always grumpy ;)

He's not grumpy, he's direct.

And helpful. It's good to know that people will get educated about top
posting, multiposting vs. crossposting, sccces, meaningful subject lines and
associated netiquette even when they don't/won't read the FAQs.

- Lew
 
 
wesley.hall





PostPosted: 2006-12-22 0:01:00 Top

java-programmer >> reflect field
Lew wrote:
> email***@***.com wrote:
> > You know, it amazes me how many people post in this group asking for
> > help and say something like...
> >
> > "I wrote this code (which I have posted), it works.... but some other
> > code (which I haven't posted) doesn't work. Please help!".
> >
> > I am starting to understand why Andrew Thompson is always grumpy ;)
>
> He's not grumpy, he's direct.
>
> And helpful. It's good to know that people will get educated about top
> posting, multiposting vs. crossposting, sccces, meaningful subject lines and
> associated netiquette even when they don't/won't read the FAQs.
>
> - Lew

I know, I was just kidding, hence the emoticon :o)

 
 
Daniel Pitts





PostPosted: 2006-12-22 0:34:00 Top

java-programmer >> reflect field
email***@***.com wrote:
> email***@***.com wrote:
> > Hi all,
> >
> > I want to get value of string variable in a class, and field it with
> > new strings like this :
> >
> > EXample
> >
> > public class helloWold()
> > {
> > String myString1 = "test1";
> > String myString2 = "test2";
> > String myString3 = "test3";
> > String myString4 = "test4";
> > }
> >
> >
> > public static void main(String[] args) {
> > Field myField[] = helloWold().class.getFields();
> >
> > for (int i = 0; i < myField.length; i++)
> > {
> > System.out.println(myField[i].getName()); //get value
> > }
> > }
> >
> > Actually I get the value, but i didn't know how to field it. I try the
> > method set but i have an error
> > 'an not set java.lang.String field to java.lang.String'
> >
> > Any ideas
>
> You know, it amazes me how many people post in this group asking for
> help and say something like...
>
> "I wrote this code (which I have posted), it works.... but some other
> code (which I haven't posted) doesn't work. Please help!".
>
> I am starting to understand why Andrew Thompson is always grumpy ;)

Strangly enough, the code the OP posted is NOT valid Java code by any
means.