-3

If i want to return two Gravity values at same time in java, I do this:

private int rightCenterVertical() {
   return Gravity.RIGHT | Gravity.CENTER_VERTICAL;
}

How can that be transformed to kotlin code?

To be honest, I don't know how it's called the "|" operator from java that is used to mix two values and return both of them.

jsamol
  • 3,042
  • 2
  • 16
  • 27
NullPointerException
  • 36,107
  • 79
  • 222
  • 382

1 Answers1

3

In kotlin it is just called or so your code would look like this:

fun rightCenterVertical(): Int {
   return Gravity.RIGHT or Gravity.CENTER_VERTICAL
}
Garuno
  • 1,935
  • 1
  • 9
  • 20
  • May be worth adding that, unlike Java, it's implemented as an infix function in the standard library, not an operator in the language syntax. Kotlin docs for it are [here](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/or.html). – gidds Oct 19 '22 at 21:28
  • That is correct, but in this case it is the bitwise or operator presumably between two Ints. Kotlin docs for the bitwise or are [here](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/or.html). – Garuno Oct 20 '22 at 06:51
  • (Whoops, yes, you're right of course!) Anyway, feel free to add that into your answer. – gidds Oct 20 '22 at 09:14