Scala Unit type

前端 未结 5 1378
情深已故
情深已故 2020-12-13 18:32

I use opencsv to parse csv files, and my code is

while( (line = reader.readNext()) != null ) { .... }

I got a compiler warning saying:

5条回答
  •  一生所求
    2020-12-13 19:14

    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} ) { .... }
    

提交回复
热议问题