You are currently viewing Is there a better way to make a secondary constructor with lots of default values?

Is there a better way to make a secondary constructor with lots of default values?

For example here’s what I’m trying to do:


data class PathingPointsForUnitSquareConfiguration( val x: Int, val y: Int, val mapWidth: Int, val mapHeight: Int, val pathingPointPrecision: Float = PATHING_POINT_PRECISION, val calculateTopLeft: Boolean = true, val calculateTopRight: Boolean = true, val calculateBottomRight: Boolean = true, val calculateBottomLeft: Boolean = true ) { constructor( p: Point, mapWidth: Int, mapHeight: Int, pathingPointPrecision: Float = PATHING_POINT_PRECISION, calculateTopLeft: Boolean = true, calculateTopRight: Boolean = true, calculateBottomRight: Boolean = true, calculateBottomLeft: Boolean = true ) : this( p.x, p.y, mapWidth, mapHeight, pathingPointPrecision, calculateTopLeft, calculateTopRight, calculateBottomRight, calculateBottomLeft ) val topY: Int get() = y + 1 val rightX: Int get() = x + 1 };

Is there a better way to do this? I find it annoying because if I want to add another property I would have to copy and paste it into the secondary constructor to keep it in sync.

submitted by /u/IllTryToReadComments
[link] [comments]