Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:14:11+00:00 2026-06-08T10:14:11+00:00

Got two ways: String salary = company.getPerson(id).getData().getSalary(); String postcode = company.getPerson(id).getData().getPostCode(); or Data data

  • 0

Got two ways:

 String salary = company.getPerson(id).getData().getSalary();      
 String postcode = company.getPerson(id).getData().getPostCode();

or

Data data = company.getPerson(id).getData();    
String salary = data.getSalary();     
String postcode = data.getPostCode();

Which is the preferred way and why?
Any benefits apart from readability?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:14:14+00:00Added an answer on June 8, 2026 at 10:14 am

    Id actually prefer a third option in case the person does not exist

    Person person = company.getPerson(id);
    if(person != null) {
        Data data = person.getData();
        if(data != null) {
            String salary = data.getSalary();
            String postcode = data.getPostCode();
        }
    }
    

    It depends whether there may be null values or not. If you can guarantee there will be no null values then you can eliminate some/all of the null checks.

    As another user pointed out in the comment below there may be a case where none of the method calls can return null in which case unless performance is an issue it would really be down to personal preference in my opinion.

    I would probably still prefer to seperate them out into seperate calls as I have, even without the null checks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got two ways of fetching a bunch of data. The data is stored
I've got an ads table, with ads which can be promoted in two ways.
I've got some questions about two ways to save settings in the web.config. Appsettings
I got two data storages in my Windows Azure account. One is for the
I got two models which are related via ForeignKey in Django. (I am using
I got two gridviews in the same page, which basically displays the same type
What are the possible ways to solve a maze? Ive got two ideas, but
I have got a proj work, which works in this way... An app which
I've got a string which consists of few sentences which are in curly brackets
I would like to make function which detects/validates that a string got at least

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.