1. fun <E> log(tag: String, collection: Collection<E>?) {
    2. collection?.isEmpty().let {
    3. println("collection is empty $it")
    4. return
    5. }
    6. var sb = StringBuffer().apply {
    7. append("==========log collection==============\n")
    8. collection?.forEach {
    9. append(it).append("\n")
    10. }
    11. append("==========log collection end==============\n")
    12. }
    13. println("collecton: "+sb.toString())
    14. }

    这个判空是有问题的,永远都会都到let 代码中,因为isEmpty无论是返回true,还是false,都是对象,都会走到let中,那么应该怎么优雅的判断集合为空呢

     collection?.isEmpty().let {
                println("collection is empty $it")
                return
            }