reflect field

Z

ZaRMaS

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.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
 
W

wesley.hall

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.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 ;)
 
P

Phi

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.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
 
L

Lew

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
 
W

wesley.hall

Lew said:
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 :eek:)
 
D

Daniel Pitts

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.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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top