智能铸造,确保安全铸造

时间:2018-09-04 15:57:07

标签: kotlin

kotlin 1.2.50

我正在做一个聪明的演员,只是想知道这是否是正确的方法。由于params.bottomMargin被代码编辑器突出显示为Smart cast to android.support.v7.widget.RecyclerView.LayoutParams

    val child = parent.getChildAt(i)
    val params = child.layoutParams
    if(params is RecyclerView.LayoutParams) {
        val dividerTop = child.bottom + params.bottomMargin
        val dividerBottom = dividerTop + drawable.intrinsicHeight

        drawable.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom)
        drawable.draw(c)
    }

只是想知道我是否可以使用上面的代码来投射params to RecyclerView.LayouParams

在此先感谢

1 个答案:

答案 0 :(得分:3)

这是聪明的演员的正确用法。如果需要替代方法,也可以使用const ids = [1, 2]; const work = await Promise.all( ids.map(ajaxCall) ); // 'await' means that this won't be called until the Promise.all is finished printToScreen(work); 语句或安全的强制类型转换,例如以下示例:

when
相关问题