question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generator on kotlin secondary constructor

See original GitHub issue

secondary 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:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mhyeon-leecommented, Dec 2, 2021

@acktsap javax 나 kotlin 에 시중에 나와있는 Annotation 중에 적당한게 없을까 봤는데 딱히 없네요 Spring Data 에서 사용하는 @PersistenceConstructor 이거는 spring-data-common 의존성이 있고요

딱히 마땅한게 없다면 @ConstructorProperties 가 그나마 가이드할만할 거 같습니다. 말씀하신대로 용도가 정확히 맞지는 않는데 그렇다고 더 좋은 애노테이션이 없네요

코틀린이니까 @CosntructorProperties 가 붙어 있는 생성자를 선택하되 properties 는 애노테이션에 명시할 필요 없이 직접 생성자의 정보를 읽어도 좋을거 같습니다.

0reactions
seongahjocommented, Nov 23, 2022

Use ConstructorPropertiesArbitrartyIntrospector since 0.4.3

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found