How do I make the method return type generic?

前端 未结 19 2648
無奈伤痛
無奈伤痛 2020-11-22 06:16

Consider this example (typical in OOP books):

I have an Animal class, where each Animal can have many friends.
And subclasses like

19条回答
  •  春和景丽
    2020-11-22 06:31

    Additionally you can ask the method to return the value in a given type this way

     T methodName(Class var);
    

    More examples here at Oracle Java documentation

提交回复
热议问题