How to justify why an unchecked cast is okay, regarding Copyable getObjectCopy()

后端 未结 1 834
被撕碎了的回忆
被撕碎了的回忆 2021-01-21 00:06

(This is a follow-up to my previous question.)

I have an interface called Copyable, which has a single function

Copyable getObjectCopy();
         


        
1条回答
  •  时光说笑
    2021-01-21 00:27

    We are in Java 5+ world now! User Generics.

    You can change the signature of Copyable to something like:

    interface Copyable {
        T getObjectCopy();
    }
    

    Now your ValidateValue value would be something like:

    puvlic class ValidateValue implements Copyable> {
        ...
    }
    

    and everyone (including the compiler) would be happy!

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