Results 1 to 3 of 3
  1. #1
    james_gould is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default MyInstance.myMethod().myMethod() ??

    Hello. This question is hard for me to explain but here goes...

    What makes the following possible?

    Java Code:
    StringBuilder StrBuilder = new StringBuilder();
    StrBuilder.append(arguments[0]).append(arguments[1]);
    When I create my own class and make a call to...
    Java Code:
    MyInstance.myMethod().myMethod();
    ...I get a compiler error. How do I get the object to be able to handle the numerous appended calls to methods?

    Compiler error is as follows:
    ClassWithTwoMethods.java:24: error: void cannot be dereferenced
    AnInstance.firstMethod().firstMethod().firstMethod ();
    ^
    1 error

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,778
    Blog Entries
    7
    Rep Power
    21

    Default Re: MyInstance.myMethod().myMethod() ??

    The append(...) method in the StringBuilder class returns that StingBuilder again; your method returns a void (nothing).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    james_gould is offline Member
    Join Date
    Apr 2012
    Posts
    2
    Rep Power
    0

    Default Re: MyInstance.myMethod().myMethod() ??

    Thanks so much for the prompt reply and answer is so simple. Have a good night.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •