Nothing is the type name. This is a subtype of all other types. You cannot call methods from Nothing , you need to specify the exact type ( (bc: ExactType).broadcast(message) ). Nothing has no instances. The method that returns Nothing will never actually return a value. This will ultimately lead to an exception.
Type inference
Definition of lookup :
abstract public <T extends Broadcaster> T lookup(Object id);
in scala, this definition is as follows:
def lookup[T <: Broadcaster](Object id): T
There is no type parameter specified in the lookup method. In this case, the compiler will output this type of parameter as the most specific type - Nothing :
scala> def test[T](i: Int): T = ??? test: [T](i: Int)T scala> lazy val x = test(1) x: Nothing = <lazy> scala> lazy val x = test[String](1) x: String = <lazy>
You can specify a type parameter as follows:
val bc = BroadcasterFactory.getDefault().lookup[Broadcaster](_broadcasterId)
Implementation project
During development, a lookup can be "implemented" as follows:
def lookup(...) = ???
??? returns Nothing .
You must specify either the result type of the lookup method, like this: def lookup(...): <TypeHere> = ... or type bc : val bc: <TypeHere> = .
source share