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
  • 148,279
  • 62
  • 259
  • 315

1 Answers1

-1
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG)

    paint.color = Color.YELLOW
    paint.style = Paint.Style.STROKE
    paint.strokeWidth = 5.0f
blackapps
  • 8,011
  • 2
  • 11
  • 25