微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我怎样才能使用java运算符“| “在科特林?

我该如何使用此运算符?
int a = 5 | 10;
int b = 5 & 10;

它可以在Java中使用,但在Kotlin中看不到它.

解决方法

您已为它们命名了功能.

直接从Kotlin docs

As of bitwise operations,there’re no special characters for them,but just named functions that can be called in infix form.

例如:

val x = (1 shl 2) and 0x000FF000

Here is the complete list of bitwise operations (available for Int and Long only):

shl(bits) – signed shift left (Java's <<)
shr(bits) – signed shift right (Java's >>)
ushr(bits) – unsigned shift right (Java's >>>)
and(bits) – bitwise and
or(bits) – bitwise or
xor(bits) – bitwise xor
inv() – bitwise inversion

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐