Cloning with generics

后端 未结 6 625
栀梦
栀梦 2020-12-08 17:19

Once upon a time there was a class:

public class Scope> implements Comparable>, Clon         


        
6条回答
  •  孤街浪徒
    2020-12-08 17:47

    This is one reason why no one likes Cloneable. It's supposed to be a marker interface, but it's basically useless because you can't clone an arbitrary Cloneable object without reflection.

    Pretty much the only way to do this is to create your own interface with a public clone() method (it doesn't have to be called "clone()"). Here's an example from another StackOverflow question.

提交回复
热议问题