3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

kotlin対話型実行環境を動作させるまで

Posted at

簡単にkotlinのコードを試してみたいことがあり環境を整えてみました。

手順1. インストール

上記のURLからインストールが可能です。
普段はhomebrewを使用してインストールをしているので、今回もhomebrewを使用してインストールをします。

homebrewがなければ、こちらからインストール。

$ brew update
$ brew install kotlin

インストール完了しました。

手順2. 起動

$ kotlinc-jvm
Welcome to Kotlin version 1.4.10 (JRE 11.0.7+10)
Type :help for help, :quit for quit
>>> 

これで起動は完了したので、実際にコードを入力。

>>> println("Hello,World!")
Hello,World!
>>> val map = mapOf("リンゴ" to 80, "ミカン" to 100, "メロン" to 1000)
>>> map.forEach { (key, value) ->
...    println("$key は $value 円です。")
... }
リンゴ は 80 円です。
ミカン は 100 円です。
メロン は 1000 円です。
>>> :quit

しっかり動作が確認できました。

使用する機会がほぼないと思いますが、実際にファイルに記述してコンパイル→jarファイルの実行まで出来るとのこと。
JVM上で動くのでJREやJDKが入っていないと動作しないので、注意が必要です。

基本はIDEで進めていきますが、どう処理するべきか悩んだときは、勉強用として、とりあえず対話型の環境で色々試してみています。

3
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?