Exception in thread "main" java.lang.IndexOutOfBoundsException: 3
at scala.collection.LinearSeqOps.apply(LinearSeq.scala:117)
at scala.collection.LinearSeqOps.apply$(LinearSeq.scala:114)
at scala.collection.immutable.List.apply(List.scala:79)
at index.App$.lastUserId(App.scala:6)
def lastUserId(userIds: List[Int]): Int =
userIds(userIds.length)
The collection of user ids is described by the Scala List. This is zero-indexed, so the last user id is found at index N - 1 where N is the length of the list. When an index greater than this number is used, an exception is raised and the program exits.
The collection of user ids is described by the Scala List. This is zero-indexed, so the last user id is found at index N - 1 where N is the length of the list. When an index greater than this number is used, an exception is raised and the program exits.
Notice we don't mention solid state physics
The computer:
def lastUserId(userIds: List[Int]): Int =
userIds(userIds.length)
Exception in thread "main" java.lang.NoClassDefFoundError:
scalacache/CacheConfig$
at utils.UserIds$.cache(UserIds.scala:12)
at index.App$.index(App.scala:15)
at index.index.main(App.scala:13)
Caused by: java.lang.ClassNotFoundException:
scalacache.CacheConfig$
at java.base/jdk.internal.loader...
import utils.UserIds
...
val cache = UserIds.cache[IO]
Scala compiled the program, but fails to run it. Perhaps our Scala compiler didn't compile scalacache properly?
SBT threw an error when running the program. This is a problem with out SBT configuration.
The error originates in scalacache. There's a bug in scalacache, or in the way we're using it.
Think about your thinking