I am trying to compare two int values with a method.
I have put two get methods after each other because the array[i] is a list of person objects and gethouse only gives the house object, the houseid is in another class.
I’m wondering if I can set up two get() methods after each other?
public Person findperson( int houseId ){
for ( int i = 0; i < array.length; i++ ){
if ( array[ i ].gethouse().gethouseID() == houseId ){
return array[ i ];
}
}
return null;
}
You can do this.
However I don’t think it’s good practise.
a.getB().getC().getD(), any one of these can return null. You can’t tell which returned null in the resulting stack trace (excluding the last invocation returning null, which is fine). You may wish to use the null object pattern in this scenario.Personobject to do the heavy lifting.