Generic get method. Takes a Class as parameter and tries to cast to it