hotzen
hotzen

Reputation: 2873

How to work with data: Any of type java.util.Arrays.ArrayList?

Using the AWT.Transferable, I get an argument "data: Any" which is actually of type java.util.Arrays.ArrayList. How can I cast the "data" explicitly to this type? It seems I do not have any access to the "ArrayList"-Type itself...

Upvotes: 0

Views: 361

Answers (2)

Daniel C. Sobral
Daniel C. Sobral

Reputation: 297265

This

data match {
  case jlist: java.util.List[_] => // I got an java.util.list!
  case _ => // oops, unexpected!
}

is type-safe, which doesn't happen to be the case of asInstanceOf.

Upvotes: 1

oxbow_lakes
oxbow_lakes

Reputation: 134310

Why do you need the class explicitly? Couldn't you use the java.util.List interface?

data.asInstanceOf[java.util.List[_]]

Note that casting is not encouraged, which is why it looks so awful in Scala!

Upvotes: 1

Related Questions