0
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

データクラスに10以上のパラメーターがあり、空のコンストラクタでデータクラスを初期化して、値をセットする方法が調べても出てこなかったので、メモを残しておく。

データクラスの生成方法 :

data class XxxData(
        var updated_on: String,
        var tags: List<String>,
        var description: String,
        var user_id: List<Int>,
        var status_id: Int,
        var title: String,
        var created_at: String,
        var data: HashMap<*, *>,
        var id: Int,
        var counts: LinkedTreeMap<*, *>,
)

使い方 :

val activity =  Activity();
activity.title = "New Computer"
sendToServer(activity)

こうやって、パラメータに値をセットしておくことで、空のコンストラクタを生成することができるようになる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?