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

前端 未结 5 812
野的像风
野的像风 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条回答
  •  一生所求
    2020-12-02 08:56

    You can simply convert the List using Scala's JavaConverters:

    import scala.collection.JavaConverters._
    
    def findAllQuestion():List[Question] = {
      questionDao.getAllQuestions().asScala
    }
    

提交回复
热议问题