fun <E> log(tag: String, collection: Collection<E>?) {collection?.isEmpty().let {println("collection is empty $it")return}var sb = StringBuffer().apply {append("==========log collection==============\n")collection?.forEach {append(it).append("\n")}append("==========log collection end==============\n")}println("collecton: "+sb.toString())}
这个判空是有问题的,永远都会都到let 代码中,因为isEmpty无论是返回true,还是false,都是对象,都会走到let中,那么应该怎么优雅的判断集合为空呢
collection?.isEmpty().let {
println("collection is empty $it")
return
}
