Scala 单位类型 [英] Scala Unit type
本文介绍了Scala 单位类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用opencsv解析csv文件,我的代码是
I use opencsv to parse csv files, and my code is
while( (line = reader.readNext()) != null ) { .... }
我收到一个编译器警告说:
I got a compiler warning saying:
comparing values of types Unit and Null using `!=' will always yield true
[warn] while( (aLine = reader.readNext()) != null ) {
我应该怎么做while循环?
How should I do the while loop?
推荐答案
在你的例子中 (line = reader.readNext()) 是一个返回类型 Unit 的函数式文字.您可以按如下方式重写代码:
In your case (line = reader.readNext()) is a functional literal that returns type Unit. You may rewrite the code as follows:
while( {line = reader.readNext(); line!= null} ) { .... }
这篇关于Scala 单位类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文