Warning for generic varargs

前端 未结 4 1950
暗喜
暗喜 2021-01-18 01:31

I have declared the following method:

private void mockInvokeDBHandler(Map... rows) {
    List> allRows         


        
4条回答
  •  梦毁少年i
    2021-01-18 01:47

    You could lower the burden of using a List instead of varargs by using some builder interface (e.g. like the one I'm using). Using this CollectionBuilder, it would become something like this:

    mockInvokeDBHandler(CollectionBuilder.>list().add(map1).add(map2).get());
    

    it's prettier without generic args though:

    import static at.molindo.utils.collections.CollectionBuilder.list
    
    List list = list(String.class).add("foo").addAll(set).get();
    

    It's certainly longer as the varargs solution, but anyway pretty handy at times.

提交回复
热议问题