Reputation: 5904
Can i convert in some way this method from boolean to int? so when i will call the method instead return true or false i can return 1 or 0:
public boolean openMode() {
return Settings.System.getBoolean(contxt.getConentResolver(), Setting.System.START_METHOD, true);
}
Upvotes: 1
Views: 360
Reputation: 38098
A shorter form, using a "ternary operator":
public int openMode()
{
boolean value = Settings.System.getBoolean(contxt.getConentResolver(), Setting.System.START_METHOD, true);
return (value == true ? 1 : 0);
}
Upvotes: 1
Reputation: 4849
public int openMode(){
boolean value = Settings.System.getBoolean(contxt.getConentResolver(), Setting.System.START_METHOD, true);
if(value){
return 1;
}
else{
return 0;
}
}
Upvotes: 3
Reputation: 2619
Unlike other programming languages like C, java does not recognizes 1 or 0 as true or false ( or boolean in short). So the return type of this method has to be boolean it self, you can not return 1 or 0 unless you change the method's return type. However, if you can change the method signature , you can change the return type to int and return 1 for true and 0 for false. example :
public int openMode(){
return (Settings.System.getBoolean(contxt.getConentResolver(), Setting.System.START_METHOD, true))?1:0 ;
}
Upvotes: 1