How to replace run-time instanceof check with compile-time generics validation

前端 未结 6 957
有刺的猬
有刺的猬 2021-01-22 11:52

Got a little puzzle for a true Java Generics specialist... ;)

Let\'s say I have the following two interfaces:

interface Processor {
    void process(Foo          


        
6条回答
  •  深忆病人
    2021-01-22 12:27

    No, that's not what Java Generics were designed to do.

    Also, in my opinion, the need for the type check indicates a problem with the design. I'd suggest trying to re-design it so that this is not necessary.

提交回复
热议问题