LoginSignup
0
0

More than 3 years have passed since last update.

[Kotlin] 基本Typeを調べてみよう

Posted at

Kotlin???

最近、大学の先輩から「Kotlin」の話をよく聞いています。
少し、興味があったので、調べてみました。

Kotlinは、
JetBrainsから2011年に公開したプログラミング言語。
Android、Spring、Tomcat、JavaScript、Java EE、HTML5、iOSなどを開発する際に、使用することができる。
2017年にGoogleがAndroidの公式言語でKotlinを追加。
2018年にKakao TalkメッセージングサーバーにKotlinを使ってみた結果、コード量が飛躍的に減少し、生産性が大幅に向上。

Kotlin Type定義

Kotlinは、Typeを使用します。Javaと比較してみると、すべて大文字で開始します。

Java Type Kotlin Type Kotlin Type bit
double   Double 64
float   Float 32
long   Long 64
int   Int 32
short   Short 16
byte   Byte 8
java_sample1.java
long a = 100;
int b = (int) a;
kotlin_sample1.kt

val a: Long = 100
val b: Int = a // ERROR

val b: Int = a.toInt()
val b = a.toInt()

Typeを変換するためには、
toInt()みたいなオプションが必要です。

Stringの変換はこんな風にします。

kotlin_sample2.kt
val string_sample: String = "123"
val int_sample = Integer.parseInt(string_sample)

次回は、基本的な文法について説明します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0