How to use scala.collection.immutable.List in a Java code

前端 未结 4 1926
轮回少年
轮回少年 2020-12-17 15:17

I need to write a code that compares performance of Java\'s ArrayList with Scala\'s List. I am having a hard time getting the Scala List

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 15:37

    I think the easiest route would be to start with a java interface and implement that in scala. For example create a java.util.List-implementation around the scala list in scala. Typically like this:

    class ScalaList[T](val ts: T*) extends java.util.List[T] {
    
      // Add all the methods, but implement only the neccessary ones
      // Add all ts
    
    }
    

提交回复
热议问题