Help us understand the problem. What is going on with this article?

kotlinでenum classを使う

More than 3 years have passed since last update.

数字から文字列を得たいとき、
(例えば5を指定して, Oneを文字列として得たいとき)

kotlin
enum class Financing(val rawValue :Int)  {
    One(5),
    Revolving(6),
    Two(7)
}
// 使う
Financing.values().filter { 5 == it.rawValue }.first() // => One (Financing型)
Financing.values().filter { 5 == it.rawValue }.first().toString() // => One(String型)

swiftコードをkotlinに変換しているとき、

kotlin
class Compass {
    enum class Direction(val rawValue: Int)  {
        NORTH(1),
        SOUTH(2),
        WEST(3),
        EAST(4)
    }
}

// 使う
Compass.Direction.NORTH.rawValue // => 1
swift
class Compass {
    enum Direction: Int  {
        NORTH = 1
        SOUTH
        WEST
        EAST
    }
}

// 使う
Compass.Direction.NORTH.rawValue // => 1
stvjbz
jubileeworks
「毎日に、新しい"なくてはならない"を創る」を経営理念に掲げ、共有カレンダーサービス TimeTree の開発・運営をしています。
https://timetreeapp.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした