Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: methodName().methodName2()??

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default methodName().methodName2()??

    This must be a simple question to many people on this forum... but i'm here scratching my head...

    This line was taken from Android sample project (NotesList) onCreate() method...

    Cursor cursor = managedQuery(getIntent().getData(), PROJECTION,
    null, null, NoteColumns.DEFAULT_SORT_ORDER);

    I understand calling methods by their respective class name and method name as so:
    someClass.someMethod();

    but I can't quite grasp this idea where you call method().method2()...

    can someone please explain what is expected when you call methods like this?
    do i expect to get some return value from the first method and that value to be passed on to the next method?

    Thanks in advance

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,147
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: methodName().methodName2()??

    method().method2()
    The first method: method() would return an instance of a class with a method: method2
    Read the API doc for method() to see what it returns.

    If you coded it in two statements it might be clearer:

    AClass anObject = method();
    anObject.method2();

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: methodName().methodName2()??

    Thank you for your response!

    I went on and posted in another forum with same question and I've gotten a fairly simple but to the bullet answer.
    The user told me this is called 'method chaining'. So, I went on and googled.

    And with your explanation on top of what I found, i've got a good understanding.

    Thank you again and hope this helps some ppl out there.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,147
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: methodName().methodName2()??

    It's good manners to post links to other threads where you have posted the same question. Then all can see the various answers and save time making an answer if that answer has already been posted on the other forum.

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: methodName().methodName2()??

    Sure. Here's the link.

    Android/Java Question: Seeking help in understanding a line of code from NotesList example. - Stack Overflow

    hope it helps!

Tags for this Thread