Jump to content

what does boolean mean in this function?

JoneLoveIT
Go to solution Solved by Eigenvektor,
15 hours ago, JoneLoveIT said:

but it has to be something that is true or false right? which one that is referring to that has to be true or false?

Yes, a method with a return type of boolean must return true or false at some point. This happens with the "return" keyword. In this particular case, the "return" keyword is followed by another method call, which means this method's return type must also be boolean.

 

override fun onSupportNavigateUp(): Boolean {
    val navController = this.findNavController(R.id.myNavHostFragment)

    // This line returns a value from the current method. Since this method's return type is Boolean
    // this must be a boolean value. It is calling another method here, so that method's return
    // value must also be Boolean. It would not be legal to call a method that, for example, returns
    // a String instead. So this method returns whatever boolean value is returned by "navigateUp".
    return navController.navigateUp()
}

 

It's the declaration of the fuction's return value, which can be either true or false.

 

In Kotlin the return value is declared after a method's name and arguments, just as it is declared after a variable's name.

 

The Java equivalent would be:

@Override
public boolean onSupportNavigationUp() {

 

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

16 minutes ago, Eigenvektor said:

It's the declaration of the fuction's return value, which can be either true or false.

 

In Kotlin the return value is declared after a method's name and arguments, just as it is declared after a variable's name.

 

The Java equivalent would be:


@Override
public boolean onSupportNavigationUp() {

 

but it has to be something that is true or false right? which one that is referring to that has to be true or false?

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, JoneLoveIT said:

but it has to be something that is true or false right? which one that is referring to that has to be true or false?

When a method has a return value of boolean, it means the outcome can be either True or False.

 

In this method, it looks like navController.navigateUp() will supply a true or false value.

Community Standards || Tech News Posting Guidelines

---======================================================================---

CPU: R5 3600 || GPU: RTX 3070|| Memory: 32GB @ 3200 || Cooler: Scythe Big Shuriken || PSU: 650W EVGA GM || Case: NR200P

Link to comment
Share on other sites

Link to post
Share on other sites

15 hours ago, JoneLoveIT said:

but it has to be something that is true or false right? which one that is referring to that has to be true or false?

Yes, a method with a return type of boolean must return true or false at some point. This happens with the "return" keyword. In this particular case, the "return" keyword is followed by another method call, which means this method's return type must also be boolean.

 

override fun onSupportNavigateUp(): Boolean {
    val navController = this.findNavController(R.id.myNavHostFragment)

    // This line returns a value from the current method. Since this method's return type is Boolean
    // this must be a boolean value. It is calling another method here, so that method's return
    // value must also be Boolean. It would not be legal to call a method that, for example, returns
    // a String instead. So this method returns whatever boolean value is returned by "navigateUp".
    return navController.navigateUp()
}

 

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×