How to convert a java.util.List to a Scala list

前端 未结 5 814
野的像风
野的像风 2020-12-02 08:01

I have this Scala method with below error. Cannot convert into a Scala list.

 def findAllQuestion():List[Question]={
   questionDao.getAllQuestions()
 } 
         


        
5条回答
  •  Happy的楠姐
    2020-12-02 08:55

    Import JavaConverters , the response of @fynn was missing toList

    import scala.collection.JavaConverters._
    
    def findAllQuestion():List[Question] = {
      //           java.util.List -> Buffer -> List
      questionDao.getAllQuestions().asScala.toList
    }
    

提交回复
热议问题