reflect field

Discussion in 'Java' started by ZaRMaS@gmail.com, Dec 21, 2006.

  1. Guest

    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
     
    , Dec 21, 2006
    #1
    1. Advertisements

  2. Guest

    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.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 ;)
     
    , Dec 21, 2006
    #2
    1. Advertisements

  3. Phi Guest

    wrote:
    > 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.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
     
    Phi, Dec 21, 2006
    #3
  4. Lew Guest

    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
     
    Lew, Dec 21, 2006
    #4
  5. Guest

    Lew wrote:
    > 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 :eek:)
     
    , Dec 21, 2006
    #5
  6. Daniel Pitts Guest

    wrote:
    > 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.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.
     
    Daniel Pitts, Dec 21, 2006
    #6
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sunil Thomas
    Replies:
    0
    Views:
    608
    Sunil Thomas
    Sep 29, 2003
  2. =?Utf-8?B?Unlv?=
    Replies:
    0
    Views:
    618
    =?Utf-8?B?Unlv?=
    Nov 21, 2005
  3. Mike
    Replies:
    2
    Views:
    597
  4. =?Utf-8?B?SmViQnVzaGVsbA==?=

    How to Make Code-Behind Reflect Changes To Designer?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Dec 14, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    533
  5. =?Utf-8?B?SlQ=?=
    Replies:
    1
    Views:
    3,916
    Hansen
    Jun 29, 2011
  6. Nicky
    Replies:
    3
    Views:
    463
    Gordon Beaton
    Jan 25, 2007
  7. Sound
    Replies:
    2
    Views:
    752
    Randy Webb
    Sep 28, 2006
  8. jr
    Replies:
    3
    Views:
    695
Loading...