Java equivalent of the Kotlin's secondary constructor "apply"

764 views Asked by At

I am having a problem. I need something similar to Kotlin's secondary constructor "apply" in Java. Kotlin:

private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
    color = Color.YELLOW;
    style = Paint.Style.STROKE
    strokeWidth = 5.0f
}

I expect something like this in Java:

private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG).apply{
    color = Color.YELLOW
    style = Paint.Style.STROKE
    strokeWidth = 5.0f
}
1

There are 1 answers

0
blackapps On
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG)

    paint.color = Color.YELLOW
    paint.style = Paint.Style.STROKE
    paint.strokeWidth = 5.0f