Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Default Constructor Creation Option #409

Open
Danc2050 opened this issue Nov 30, 2022 · 1 comment
Open

Enable Default Constructor Creation Option #409

Danc2050 opened this issue Nov 30, 2022 · 1 comment

Comments

@Danc2050
Copy link

Danc2050 commented Nov 30, 2022

In the case when we want to send a class out as a Request, it would be useful to create a constructor with default arguments in some cases, which we could change later. For example, see constructor() at the bottom of this code:

data class Activity(
    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<*, *>
) {
    constructor() : this("", emptyList(), 
                         "", emptyList(), -1, 
                         "", "", hashMapOf<Any, Any>(), 
                         -1, LinkedTreeMap<Any, Any>()
                         )
}
@wuseal
Copy link
Owner

wuseal commented Nov 30, 2022

Enable init with default value option in settings and then it will generate data class with init value, the effect is the same as your descriptions

When data class all fields initial with default value it will auto has a default construct that no need pass parameters when new a data class object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants