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

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

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

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:
    520
    Sunil Thomas
    Sep 29, 2003
  2. Raterus
    Replies:
    0
    Views:
    426
    Raterus
    Jun 2, 2004
  3. Nicky
    Replies:
    3
    Views:
    359
    Gordon Beaton
    Jan 25, 2007
  4. Sound
    Replies:
    2
    Views:
    428
    Randy Webb
    Sep 28, 2006
  5. jr
    Replies:
    3
    Views:
    405
Loading...

Share This Page