0

I am trying to make a expandable recyclerview with model data. But I am getting a signature error. Tried different solutions but didn't work.How can i set JvmName to a constructor?

Error: Platform declaration clash: The following declarations have the same JVM signature ( (ILjava/util/List;Z)V):

RowModel class:

class RowModel {
companion object{

    @IntDef(WEB_MENU, CHILD, CHILDX, CHILDXX)
    @Retention(AnnotationRetention.SOURCE)
    annotation class RowType

    const val WEB_MENU = 1
    const val CHILD = 2
    const val CHILDX = 3
    const val CHILDXX = 4

}
@RowType var type : Int
lateinit var webMenuItem : List<WebMenuItem>
lateinit var child: List<Child>
lateinit var childX: List<ChildX>
lateinit var childXX: List<ChildXX>
var isExpanded : Boolean

constructor (@RowType type : Int, webMenuItem: List<WebMenuItem>, isExpanded : Boolean = false){
    this.type = type
    this.webMenuItem = webMenuItem
    this.isExpanded = isExpanded
}


constructor(@RowType type : Int, child: List<Child>, isExpanded : Boolean = false){
    this.type = type
    this.child = child
    this.isExpanded = isExpanded
}

constructor(@RowType type : Int, childX: List<ChildX>, isExpanded : Boolean = false){
    this.type = type
    this.childX = childX
    this.isExpanded = isExpanded
}


constructor(@RowType type : Int, childXX: List<ChildXX>, isExpanded : Boolean = false){
    this.type = type
    this.childXX = childXX
    this.isExpanded = isExpanded
}

}

webMenuItem class:

class WebMenuItem {
val authFunctionTag: String = ""
val callFunctionName: Any = ""
val childs: MutableList<Child> = mutableListOf()
val id: Int = Int.MIN_VALUE
val isQueryWindow: Boolean = false
val menuIcon: String = ""
val menuName: String = ""
val queryServiceName: Any = ""
val queryTableName: Any = ""
val queryUniqColumnName: Any = ""
val queryUniqFieldName: Any = ""
val menuOrder: Int = ""
}

Child class:

class Child{
val authFunctionTag: String = ""
val callFunctionName: String = ""
var childs: List<ChildX> = mutableListOf()
val id: Int = Int.MIN_VALUE
val isQueryWindow: Boolean = false
val menuIcon: String = ""
val menuName: String = ""
val menuOrder: Int = Int.MIN_VALUE
val queryServiceName: String = ""
val queryTableName: String = ""
val queryUniqColumnName: String = ""
val queryUniqFieldName: String = ""
}

ChildX class:

class ChildX{
val authFunctionTag: String = ""
val callFunctionName: String = ""
var childs: List<ChildXX> = mutableListOf()
val id: Int = Int.MIN_VALUE
val isQueryWindow: Boolean = false
val menuIcon: String = ""
val menuName: String = ""
val menuOrder: Int = Int.MIN_VALUE
val queryServiceName: String = ""
val queryTableName: String = ""
val queryUniqColumnName: String = ""
val queryUniqFieldName: String = ""
}

ChildXX class:

class ChildXX{
val authFunctionTag: String = ""
val callFunctionName: String = ""
var childs: List<Any> = mutableListOf()
val id: Int = Int.MIN_VALUE
val isQueryWindow: Boolean = false
val menuIcon: String = ""
val menuName: String = ""
val menuOrder: Int = Int.MIN_VALUE
val queryServiceName: String = ""
val queryTableName: String = ""
val queryUniqColumnName: String = ""
val queryUniqFieldName: String = ""
}
alpertign
  • 296
  • 1
  • 4
  • 13
  • Not possible. Constructors have a special name, and you can't change it. How about writing one (private) constructor, and 4 factory functions instead? – Sweeper Sep 05 '21 at 10:27
  • Does this answer your question? [Kotlin thinks that two methods have the same JVM signature, but the actually don't](https://stackoverflow.com/questions/51580168/kotlin-thinks-that-two-methods-have-the-same-jvm-signature-but-the-actually-don) – Zoe Sep 09 '21 at 12:04
  • Seems like it is the true answer but I changed my approach it is totally different now. – alpertign Sep 27 '21 at 13:12

1 Answers1

0

Kotlin (like Java) has type erasure. The parameter with type List<Child> will be erased to List<*> after compilation, hence all your constructor overloads have the same JVM signature upon compilation.

You can get around this with factory functions with different names either at the top-level in the file, or in the companion object, e.g. RowModel.withWebMenuItem(...) and RowModel.withChild(...) and have the actual constructor for RowModel be what they all have in common:

constructor(@RowType type : Int, isExpanded : Boolean = false){
    this.type = type
    this.isExpanded = isExpanded
}
Can_of_awe
  • 1,431
  • 1
  • 11
  • 17
  • Thank you for your answer seems like it is true but I changed my approach to this problem This answer is still helpful tho – alpertign Sep 27 '21 at 13:17