How can you pass a List to a method?

前端 未结 2 725
醉酒成梦
醉酒成梦 2021-01-01 17:13

I have a servlet that, passed on query params, gets a list of objects from the DAO, turns the list into JSON, and sends it back in the response. Every list is made of object

相关标签:
2条回答
  • 2021-01-01 17:35

    Why don't just use

    private String getListAsJson(List<JsonEnabled> list) { ... }
    

    ?

    0 讨论(0)
  • 2021-01-01 17:43

    For generic wildcards the keyword extends works for both classes and interfaces:

    private String getListAsJson(List<? extends JsonEnabled> list) { ... }
    

    extends has slightly different meaning when used for defining generic bounds - it essentially translates to "is, or extends, or implements".

    0 讨论(0)
提交回复
热议问题