0

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
}
hsz
  • 143,040
  • 58
  • 252
  • 308

1 Answers1

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

    paint.color = Color.YELLOW
    paint.style = Paint.Style.STROKE
    paint.strokeWidth = 5.0f
blackapps
  • 6,227
  • 2
  • 6
  • 19