将代码从 Java 更改为 Kotlin 后注释未正确转换
Annotations not converted properly after changing code from Java to Kotlin
将一些 Java 代码转换为 Kotlin(以创建 ReplacementSpan)后,返回了与注释相关的错误。
from
在@IntRange(from = 0)
构造函数中returns报错:
'IntRange' is not an annotation class | Cannot find a parameter with this name: from
import android.graphics.Canvas
import android.graphics.Paint
import sun.swing.SwingUtilities2.drawRect
import android.text.style.ReplacementSpan
class HrSpan : ReplacementSpan() {
override fun getSize(
paint: Paint, text: CharSequence, @IntRange(from = 0) start: Int,
@IntRange(from = 0) end: Int, fm: Paint.FontMetricsInt?
): Int {
return 0
}
override fun draw(
canvas: Canvas, text: CharSequence, @IntRange(from = 0) start: Int,
@IntRange(from = 0) end: Int, x: Float, top: Int, y: Int, bottom: Int,
paint: Paint
) {
canvas.drawRect(x, top.toFloat(), y.toFloat(), (top + 8).toFloat(), paint)
}
}
将一些 Java 代码转换为 Kotlin(以创建 ReplacementSpan)后,返回了与注释相关的错误。
from
在@IntRange(from = 0)
构造函数中returns报错:
'IntRange' is not an annotation class | Cannot find a parameter with this name: from
import android.graphics.Canvas
import android.graphics.Paint
import sun.swing.SwingUtilities2.drawRect
import android.text.style.ReplacementSpan
class HrSpan : ReplacementSpan() {
override fun getSize(
paint: Paint, text: CharSequence, @IntRange(from = 0) start: Int,
@IntRange(from = 0) end: Int, fm: Paint.FontMetricsInt?
): Int {
return 0
}
override fun draw(
canvas: Canvas, text: CharSequence, @IntRange(from = 0) start: Int,
@IntRange(from = 0) end: Int, x: Float, top: Int, y: Int, bottom: Int,
paint: Paint
) {
canvas.drawRect(x, top.toFloat(), y.toFloat(), (top + 8).toFloat(), paint)
}
}