3
scala> Try(Class.forName("scala.util.Try")) warning: there was one feature warning; re-run with -feature for details res54: scala.util.Try[Class[?0]] forSome { type ?0 } = Success(class scala.util.Try) 

Can someone please explain what is the ?0 type? When I try to use it in code, doesn't compile.

val tryMongo: Try[Class[?0]] = Try(Class.forName(MONGO_COLLECTION_CLASS))

1 Answer 1

4

This usually appears for existential type, so try:

scala> val tryMongo: Try[Class[`?0`]] forSome { type `?0`} = Try(Class.forName("scala.util.Try")) tryMongo: scala.util.Try[Class[?0]] forSome { type ?0 } = Success(class scala.util.Try) 

Note that you can choose any name, like T or A instead of ?0 - it's just a convention for compiler messages (? was probably chosen because same sign used in Java). You can also use a shortcut XXX[_], which is completely equivalent to XXX[T] forSome { type T }:

scala> val tryMongo: Try[Class[_]] = Try(Class.forName("scala.util.Try")) tryMongo: scala.util.Try[Class[_]] = Success(class scala.util.Try) 
Sign up to request clarification or add additional context in comments.

2 Comments

What's the forSome { type ?0}? Anonymous type or something?
@AbhijitSarkar here is some explanation: drmaciver.com/2008/03/existential-types-in-scala

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.