generics - Can we have a field implementing two or more interfaces in Java? -
this question has answer here:
would possible create class this...
public class container implements serializable { private final (map<object,object> & serializable) map; public container( (map<object,object> & serializable) map) { super(); this.map = map; } .... } basically, don't want bind map implementation class , make sure implementation implements both map , serializable interface.
many idea , help.
you can define generic type parameter having required type bounds :
class container<e extends map<object,object> & serializable> implements serializable { private final e map; public container (e map) { super(); this.map = map; } }
Comments
Post a Comment