Is it possible to solve the “A generic array of T is created for a varargs parameter” compiler warning?

前端 未结 8 1652
Happy的楠姐
Happy的楠姐 2020-11-28 04:31

This is a simplified version of the code in question, one generic class uses another class with generic type parameters and needs to pass one of the generic types to a metho

8条回答
  •  萌比男神i
    2020-11-28 05:10

    You can have overload the methods. This does not solve your problem but it minimizes the number of warnings (and yes, it's a hack!)

    class Assembler {
      void assemble(X container, Y a1) { ... }
      void assemble(X container, Y a1, Y a2) { ... }
      void assemble(X container, Y a1, Y a2, Y a3) { ... }
      void assemble(X container, Y a1, Y a2, Y a3, Y a4) { ... }
      void assemble(X container, Y... args) { ... }
    }
    

提交回复
热议问题