Kulwinder Singh
06/08/2020, 10:12 AMcopy
function of data
class have if called many times ??
for example i have data class Position(val x:Float,val y:Float)
and i'm doing copy
of this class's instance inside android's touch listener when user's finger is moved(ACTION_MOVE) like ->
var position = Position(0f, 0f)
view.setOnTouchListener { v, event ->
when (event.action){
MotionEvent.ACTION_DOWN -> /**/
MotionEvent.ACTION_MOVE -> {
position = position.copy(x =computedX,y=computedY)//how much performance impact of this ??
}
}
}
i don't want to use mutable properties for data class for some reasonsgildor
06/08/2020, 10:17 AMgildor
06/08/2020, 10:17 AMgildor
06/08/2020, 10:18 AMgildor
06/08/2020, 10:18 AMKulwinder Singh
06/08/2020, 10:19 AMgildor
06/08/2020, 10:20 AMgildor
06/08/2020, 10:20 AMgildor
06/08/2020, 10:21 AMKulwinder Singh
06/08/2020, 10:22 AMso what kind choice you have?only
copy
😉, but i was curious to know how much its going to effectgildor
06/08/2020, 10:24 AMgildor
06/08/2020, 10:25 AMonlyActuallyu in case of Position you even don’t need copy, probably call of constructor would be more explicitcopy
Kulwinder Singh
06/08/2020, 10:25 AMKulwinder Singh
06/08/2020, 10:26 AMgildor
06/08/2020, 10:27 AM@NotNull
public final Position copy(int x, int y) {
return new Position(x, y);
}
gildor
06/08/2020, 10:27 AMKulwinder Singh
06/08/2020, 10:29 AMgildor
06/08/2020, 10:31 AMKulwinder Singh
06/08/2020, 10:33 AMRyan
06/08/2020, 11:02 AM