Java Object return type vs. Generic Methods

后端 未结 4 725
甜味超标
甜味超标 2021-02-18 16:28

I saw several questions about generic return type, but none answers my question.
If there is no bound for any of the arguments, such as the following method in JayWay :

4条回答
  •  悲哀的现实
    2021-02-18 17:26

    There is nothing functionally different between the two. The byte-code will probably be identical.

    The core difference is that one uses a cast while the otrher uses generics.

    I would generally try to avoid casting if there is any alternative mechanism and as the generic form is a perfectly effective alternative I would go for that.

    // The right way.
    JsonPath.read(currentRule, "$.logged");
    

提交回复
热议问题