Nothing
is the type name. It's the subtype of all other types. You can't call methods from Nothing
itself, you have to specify exact type ((bc: ExactType).broadcast(message)
). Nothing
has no instances. Method, that returns Nothing
will, actually, never return value. It will throw an exception eventually.
Type inference
abstract public <T extends Broadcaster> T lookup(Object id);
in scala this definition looks this way:
def lookup[T <: Broadcaster](Object id): T
There is not specified type parameter in lookup
method. In this case compiler will infer this type 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 could specify type parameter like this:
val bc = BroadcasterFactory.getDefault().lookup[Broadcaster](_broadcasterId)
Draft implementation
In development process lookup
can be "implemented" like this:
def lookup(...) = ???
???
returns Nothing
.
You should specify either result type of lookup
method like this: def lookup(...): <TypeHere> = ...
or type of bc
: val bc: <TypeHere> =
.