Generator on kotlin secondary constructor
See original GitHub issuesecondary constructor에 대한 generator
한개만 있으면 그걸 사용하고 여러개가 있을 경우 annotation을 사용해서 mark
data class A(val value: Int) {
constructor() : this(0) {
// do something
}
@SecondaryConstructor // 이런 식으로
constructor(val value: String) : this(value.toInt()) {
// do something
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Kotlin secondary constructor - Stack Overflow
@Arbaz.in Generate a constructor for a class On the Code menu, click Generate ⌘N. In the Generate popup, click Constructor for Kotlin. If...
Read more >Kotlin Code Generation and Empty Constructor Preference
Kotlin Code Generation and Empty Constructor Preference #2378 ... An ugly workaround is to define the second constructor explicitally.
Read more >A Closer Look At Moshi 1.9 - Zac Sweers
In Moshi 1.9, generated adapters will now invoke constructors via the same synthetic constructor that Kotlin uses for constructors with ...
Read more >Kotlin program | Example of Secondary Constructor
Kotlin | Secondary Constructor: Here, we are implementing a Kotlin program to demonstrate the example of secondary constructor.
Read more >"Generate secondary constructor" with changed signature ...
"Generate secondary constructor" with changed signature from primary constructor ; Project, Kotlin IntelliJ IDEA plugin ; Priority, Major M ; Type, Feature F....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@acktsap javax 나 kotlin 에 시중에 나와있는 Annotation 중에 적당한게 없을까 봤는데 딱히 없네요 Spring Data 에서 사용하는
@PersistenceConstructor
이거는 spring-data-common 의존성이 있고요딱히 마땅한게 없다면
@ConstructorProperties
가 그나마 가이드할만할 거 같습니다. 말씀하신대로 용도가 정확히 맞지는 않는데 그렇다고 더 좋은 애노테이션이 없네요코틀린이니까
@CosntructorProperties
가 붙어 있는 생성자를 선택하되 properties 는 애노테이션에 명시할 필요 없이 직접 생성자의 정보를 읽어도 좋을거 같습니다.Use
ConstructorPropertiesArbitrartyIntrospector
since 0.4.3