开发者

Java generics - is it possible to restrict T to be Serializable?

开发者 https://www.devze.com 2023-03-28 22:27 出处:网络
Is it possible to make something like this? I know that implements cannot be in the <>, but I want to restrict the T to be Serializable somehow.

Is it possible to make something like this? I know that implements cannot be in the <>, but I want to restrict the T to be Serializable somehow.

public class Clazz<开发者_运维知识库;T implements Serializable> {
    ...
}


public class Clazz<T extends Serializable> {
    ...
}


Just use extends instead of implements.


Yes, just use extends instead of implements.

0

精彩评论

暂无评论...
验证码 换一张
取 消