We have a local class Z which needs to be used as below:
On compiling above code it throws error , which is :
In Java, there is no fully qualified name for local classes, thus they cannot be expressed as Reifiable (A reifiable type is a type whose type information is fully available at runtime. This includes primitives, non-generic types, raw types, and invocations of unbound wildcards). And in an instanceof expression the referenced type must be Reifiable. Now lets see how do we resolve this error.
A simple solution is to use reflection, using reflection you can use the local class without any changes.
Another way to resolve this error is to make class Z generic.