There is an interface with a method that returns a Class, like so.
public interface MyInterface {
public Class<? extends Object> returnsSomething ();
}
I have to create a class which implements the interface, like so.
public class MyClass implements MyInterface {
public Class<? extends Object> returnsSomething () {
return Object; // This is currently an error.
}
}
The return line in the implementation of returnsSomething in MyClass is incorrect. The IDE hints "cannot find symbol Object".
What correction do I need to apply in returnSomething‘s body to compile successfully?
>Solution :
Object is just the name of the class.
Object.class is the instance of the Class<Object> class that represents the Object class. See Class.
So you need:
return Object.class;